Hi All,
I have requirement where I need to remove consequent duplicate value while showing the data in grid.
i,e if values are: {"Requested", "Requested", "Pending","Sent For Approval","Approved","Pending","Approved","Approved"} the expected output is {"Requested", , "Pending","Sent For Approval","Approved","Pending","Approved"}
Here "Requested" and "Approved" are getting rejected as they are consequently occurring twice.
Discussion posts and replies are publicly visible
Hi Gaurav,You can get unique list first and then pass that to Grid.EX:{1,2,3,4,1,4,5}tryunion({1,2,3,4,1,4,5},{1,2,3,4,1,4,5}) returns :{1,2,3,4,5}
Hi Leela,
Requirement is to remove two consecutive duplicates, not all duplicates
{"Requested", "Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved", "Approved"} the expected output is {"Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved"}
You use reduce() to do this. Requires a helper function. They idea is:
If last item in list equals new value, skip it, else append it.
MAIN
a!localVariables( local!values: {"Requested", "Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved", "Approved"}, reduce( rule!SSH_ReduceHelper( list:_, newValue:_ ), {}, local!values ) )
HELPER: Inputs: list(Array of Text), newValue(Text)
if( index(reverse(ri!list), 1, "") = ri!newValue, ri!list, append(ri!list, ri!newValue) )
Try this:
a!localVariables( local!list: { "Requested", "Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved", "Approved" }, local!newList: reject( fn!isnull, a!forEach( items: local!list, expression: if( or( fv!index = 1, local!list[fv!index - 1] <> fv!item ), fv!item, null ) ) ), local!newList )
Hope it helps.
Pretty sure a!forEach() can handle this implicitly, without needing to involve legacy looping functions or helper rules. E.G.:
a!localVariables( local!values: {"Requested", "Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved", "Approved"}, a!forEach( local!values, if( fv!isFirst, fv!item, if( fv!item = local!values[fv!index - 1], {}, fv!item ) ) ) )
Result:
Note that this would collapse *all* consecutively repeated values, not just cases where there are 2 repeated items. Though it sounds like this satisfies OP's use case anyway.
Thanks Mike,
This really helped with small variation as I was using one cdt where two fields needs to be considered together.
a!localVariables( local!RequestHistory:###Query From DB###, local!uniqueHistoryData:a!forEach( local!colocationRequestHistory, if( fv!isFirst, fv!item, if( and( fv!item.statusExternal = local!RequestHistory.statusExternal[fv!index - 1], fv!item.stage = local!RequestHistory.stage[fv!index - 1], ), {}, fv!item ) ) ), local!uniqueHistoryData )