cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Recursive schema section ?

ryan-avent
Deputy Chef II
Deputy Chef II

We have a section in our output schema that is Recursive and can go down as many levels as the customer needs, doing this in java is simple however i cant seem to work out how to do this in a workato output schema.


Im looking for some way to add a reusable object section of an output like below, the documentation seems to be lacking here.


output_fields: lambda do |object_definition|

[

{name: "item", type: "array", of: "object", properties: [

{name: "id", label: "Id", type: "string"},

{name: "number", label: "Id", type: "string"},

{name: "bom", object_definitions: "bom"}

]}

]


object_definitions: {

bom: {

fields: lambda do

[

{name: "bom", type: "array", of: "object", properties: [

{name: "id", label: "Id", type: "string"},

{name: "itemNum", label: "Item Number", type: "string"},

{name: "bom", object_definitions: "bom"}

]}

]

end

}

},


The idea is so that i can have an output with a recursive section like the below without having to manualy define every level, as this can be infinate in our system.


{

"item": {

"id": "1320874150",

"number": "C-10000001",

"bom": [

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR",

"bom": [

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR",

"bom": [

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR",

"bom": [

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR"

}

]

},

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR"

},

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR"

}

]

},

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR",

"bom": [

{

"id": "421559999",

"itemNum": "ACTT-RECT-120-48-CHR"

}

]

}

]

}

]

}

}


1 REPLY 1

gary1
Executive Chef II
Executive Chef II

Hey Ryan, in my experience recursive structures won't work well with Workato because you'll never be able to access the datapills in the output tree within a recipe for use in other actions. The output structure would have to be based on the result of the query itself, which means you'd have to run the query, use it to build the output schema, and then run it again. Sounds pretty inefficient, but maybe I'm just not aware of other ways around this.


That said, I have one suggestion that might work, or at least might inspire some other ideas!


I would try to flatten the entire response into something with far less depth, because this will make iteration in a recipe much easier. For each root node in the response, you can recursively process each child node and add them into a new child array within the root node. If you include a new key to identify their direct parent ID, you could be able to reference each child node within a recipe.


In addition to identifying their direct parent, you can create breadcrumb key that identfies the full ID lineage of the child node for parsing later. Something very explicit like like "greatgreatgrandparentID-greatgrandparentID-grandparentID-parentID-myID" would make identification of each node outside of the source output very straightforward with a little parsing.


Your output schema would then be based on this flatter array. I hope this helps. If you do find another way around the issue, please share!