How to add an "extra" invoice row to order data from Airtable that is Iterated/Aggregated?

:bullseye: What is your goal?

To get an additional invoice row generated that does not exist in order data from before.

I get a new order in from Airtable and generate a new invoice into a finance system with it. The order can have multiple products that are Linked Records in Airtable. In the current setup I run the output from the Airtable Get Order module into an Iterator (iterates on price), then that output into an Array Aggregator, which output I store in a Set Variable module. These are then combined with other data to generate a new invoice with n invoice rows in the finance system.

If the order has a discount sum, I’d need to insert a new product row with the negative sum to be discounted. Thereby the invoice first lists all product rows with normal prices, then the last row says “Discount per agreement: -100 euros”.

:thinking: What is the problem & what have you tried?

I thought of replicating the Get Order output into a JSON module where I could add data dependent on something like if(discount_sum;add row;do nothing), but can’t figure out how to do that.

Or could I add another Array Aggegator after the first one, and somehow insert the new row there? But I would need to “write” the new row hard coded, since it cannot be fetched from any previous order data.

Any thoughts on how to achieve this?

Rgds,

Björn

You can do it after the aggregator with the add() function, so you don’t need a second aggregator.

Put a JSON > Parse JSON module before Set Variable. Give it the extra row, using your product rows’ keys (these are just examples):

{"row": {"description": "Discount per agreement", "price": -{{ifempty(discount_sum; 0)}}}}

Run it once so the row item shows up for mapping.

Then set your variable to if(discount_sum > 0; add(Array; row); Array). Array comes from the aggregator and row from Parse JSON. Orders without a discount keep their rows. The others get the minus row last. I haven’t tried it with your finance app, so check its price field takes a negative number.

Thank you @Abdi_Abdullahi_Muham! Tested this without the conditionalities, it seems to work great :).

Cheers!

Björn