cancel
Showing results for 
Search instead for 
Did you mean: 

Improper result after Copy/Mapper output

Madhu1
New Contributor

Hi,

Can anyone pls help me why the values after copy snap getting changed without any transofrmation as shown in below pics.
Calculate_Preview
Copy_Output

In place of copy snap i used mapper also. Then also showing incorrect values for the Order quantity and Order value.

Below expressions used to calculate totalOrderQuantity and totalOrderValue.
$orderLineItems.reduce((acc,curr)=> acc+curr.totalItemQuantity,0)
$orderLineItems.reduce((acc,curr)=> acc+(curr.itemDenomination*curr.totalItemQuantity),0)

Pls let me know if you need the .slp
Thankyou.

1 ACCEPTED SOLUTION

koryknick
Employee
Employee

Update - this issue was not related to the Array.reduce() function, but with how the target path was defined. After a short offline discussion with @Madhu1 we were able to resolve it using a Structure snap to push the results into the target object correctly.

View solution in original post

3 REPLIES 3

koryknick
Employee
Employee

Hi @Madhu1 - welcome to the Community!

Based on what you have shown as the expressions used to calculated your values, you’re getting into an issue with memory addressing. The Array.reduce() function works on the array directly, so the concurrent executions of reduce() on the same array can yield unpredictable results (as you have seen). Try the following:

[].concat($orderLineItems).reduce((acc,curr)=> acc+curr.totalItemQuantity,0)
[].concat($orderLineItems).reduce((acc,curr)=> acc+(curr.itemDenomination*curr.totalItemQuantity),0)

This should resolve the issue you are experiencing by first copying the array into a new memory address before performing the reduce() method.

koryknick
Employee
Employee

Update - this issue was not related to the Array.reduce() function, but with how the target path was defined. After a short offline discussion with @Madhu1 we were able to resolve it using a Structure snap to push the results into the target object correctly.

Thankyou @koryknick . Absolutely its working as per expected results.