cancel
Showing results for 
Search instead for 
Did you mean: 

array.map if field1 meets criteria, I want field2

aakumar
New Contributor III

IF   riskLevel=="Low Risk"

then move rd.sc to new array.  How can I can accomplish this please?

1 ACCEPTED SOLUTION

ivicakoteski
New Contributor III

Hi @aakumar,
The map() method is an iterative method and returns a new array with the values transformed by the given callback.
The current expression constructs a new array containing an object, where the object's property value is assigned the value of "rd.sc".

I have updated the expression to be more descriptive:
$SRSAPI.filter(f=>f.agrDetails.riskLevel == "Low Risk").map(element=>{"rd":{"sc":element.rd.sc}})

BR.
Ivica

View solution in original post

4 REPLIES 4

ivicakoteski
New Contributor III

Hi @aakumar ,

Please look at the attached pipeline.
Hope this helps!

BR.
Ivica

aakumar
New Contributor III

Great solution. Thank you.

But, I don't understand the Expression, it seems very complex..... 

$SRSAPI.filter(f=>f.agrDetails.riskLevel == "Low Risk").map(x=>{rd:{sc:x.rd.sc}})

I understand the filter. Could you please explain what is happening with the .map?

ivicakoteski
New Contributor III

Hi @aakumar,
The map() method is an iterative method and returns a new array with the values transformed by the given callback.
The current expression constructs a new array containing an object, where the object's property value is assigned the value of "rd.sc".

I have updated the expression to be more descriptive:
$SRSAPI.filter(f=>f.agrDetails.riskLevel == "Low Risk").map(element=>{"rd":{"sc":element.rd.sc}})

BR.
Ivica

aakumar
New Contributor III

Got it, appreciate you for taking the time to explain it to me. Thanks.