10-03-2022 05:53 AM
Hello Community,
I want to fetch ESTVERSION value after performing the group by REQUESTNUM based on condition as below:
If all records having STATUS=‘ESTIMATED’ then max(ESTVERSION) else if anyone STATUS=‘ACCEPTED’ then that ESTVERSION must be fetched. Tried with router, but not able to satisfy both the requirement.
Group_By Fields output0.json (619 Bytes)
required_output.json (260 Bytes)
Solved! Go to Solution.
10-03-2022 07:58 AM
Hi @nirupama , welcome!
I believe the following expression in a mapper will do the job:
$group.find(x=>x.STATUS == 'ACCEPTED') != null ? $group.find(x=>x.STATUS == 'ACCEPTED') : $group.sort((a,b)=> a.ESTVERSION - b.ESTVERSION).pop()
Translated version would be:
“If one object in the group has a “STATUS” field with “ACCEPTED” as value, than take that object. If not, than order the group on the “ESTVERSION” field, and take the last one, which means the max ESTVERSION.”
10-03-2022 08:52 AM
Hi @bojanvelevski What would be the mapping expression "if two or more records in the group has a “STATUS” field with “ACCEPTED” as value and it has to fetch maximum of ESTVERSION among both. And second condition remains same, all are ESTIMATED”.
10-03-2022 09:41 AM
@nirupama - Here is an updated pipeline that just breaks your problem into two steps to handle the multiple ACCEPTED records. Basically, we’ll just sort the array in the first Mapper, then select the appropriate entry in the second Mapper.
Community 13539 - Fetch value from group_2022_10_03.slp (6.9 KB)
Credit to @bojanvelevski for the slick sort() and find() criteria.
10-04-2022 01:32 AM
Hello,
This approach helped me a lot. Thank you @koryknick for providing the finest way to achieve the requirement.
Thank you @bojanvelevski