I am making a scenario where I forward invoices from one platform to another. I first retrieve a list of relevant invoices from the source platform. I use an iterator to process each invoice individually. The data looks something like this:
Now, the target platform uses essentially the same data structure, but different field names. So description needs to be details instead. Additionally, I need to filter the items to remove entries of certain types. Something like this:
newItems = [ ]
for item in invoice.items {
if item.type != 'HOURS' {
newItems.push({
details: item.description,
price: item.price,
type: item.type
})
}
}
invoice.items = newItems
I believe you could use a Parse JSON, then use an Aggregate to JSON to put it back together in JSON with your desired structure. You will need to define a custom data structure, but if you have example output you could use the schema generator to create that automatically then adjust as needed.
I should mention both the source and target data structures are fully typed, so I do not necessarily need to deal with JSON. Don’t know if that changes anything.
I tried doing this:
Get invoice list → Iterate invoices → Iterate invoice rows → Filter invoice row → Aggregate invoice rows (maps rows to target data structure) → Submit invoice
but if I understand correctly, the last step actually receives individual invoice rows. Will JSON aggregration not produce similar results, or have I misunderstood you?
Just to reiterate, in my mind I want to do something like iterate the invoices → iterate and manipulate the invoice rows → merge them back into the invoice → submit invoice to target module.
Sorry I didn’t see this reply.
Please see attached Blueprint for an example of how you can remap and filter your source JSON.
Here’s how it starts:
We parse your source JSON, iterate the Items array, filter only those with type HOURS, then aggregate back into a new JSON which is essentially the same thing except we use “details” instead of “description” for one of the keys.
I am not so sure the output format is correct, but I think you get the idea. filtering hours and remapping nested array fields.json (7.9 KB)