nirupama
3 years agoNew Contributor II
To fetch value from group by output based on different values of one field
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 anyon...
- 3 years ago
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.”