03-13-2020 11:19 AM
I am creating an integration that will take JSON from our CRM and create invoices in our ERP. One of the required fields is line number for each of the invoice lines. I am trying to generate this in the mapper snap, and I cannot figure out a way. I am really hoping that I don’t have to resort to using a script.
Solved! Go to Solution.
03-16-2020 06:32 AM
I think you can use the .map()
method on Array objects to do this since the callback will be passed the current index into the array. The following expression does this:
$lines.map((elem, index) => { lineNumber: index + 1, ...elem })
The .map()
method will iterate over each element in the $lines
array and execute the given callback function (the part that starts with (elem, index) =>
. The callback function creates a new object with the new lineNumber
property and then uses the spread operator (...elem
) to add in the properties from the original array element.
Here’s a pipeline that demonstrates this:
Community7085_2020_03_16.slp (3.6 KB)
03-16-2020 06:32 AM
I think you can use the .map()
method on Array objects to do this since the callback will be passed the current index into the array. The following expression does this:
$lines.map((elem, index) => { lineNumber: index + 1, ...elem })
The .map()
method will iterate over each element in the $lines
array and execute the given callback function (the part that starts with (elem, index) =>
. The callback function creates a new object with the new lineNumber
property and then uses the spread operator (...elem
) to add in the properties from the original array element.
Here’s a pipeline that demonstrates this:
Community7085_2020_03_16.slp (3.6 KB)
03-16-2020 06:53 AM
That did the trick. Thank you!