Hi Team,
Im trying a batch list of text items and prepare a query based on that. Below is my code snippet. With this code Im getting the last item of each list for the full batch of 50 items.
local!getAgreementIds: if( rule!APN_isBlank( index( index(local!PartnersResult, "data", null), "agreement__cr.id", null ) ), index( local!AgreementResult.data, "agreement__cr.id", null ), index( local!PartnersResult.data, "agreement__cr.id", null ) ), local!agreementDocIds: touniformstring(rule!APN_distinct(local!getAgreementIds)), local!batchedDocIds: a!forEach( items: enumerate(ceiling(length(local!agreementDocIds) / 50)), expression: local!agreementDocIds[ (fv!item * 50) + 1 : min((fv!item + 1) * 50, length(local!agreementDocIds)) ] ),
For ex: I have a list of 59 items, when I try to batch I should get 50 items in 1 batch and remaining 9 items in another batch. But Im getting last item of each batch that is 50th item in first batch and 59th item in 2nd batch. Can someone please help
Discussion posts and replies are publicly visible
The following code turns a list of things into a list of lists of things.
if( or( a!isNullOrEmpty(ri!items), a!isNullOrEmpty(ri!segmentSize) ), ri!items, a!localVariables( local!numSegments: ceiling(count(ri!items) / ri!segmentSize), if( ri!rotate, /* WITH ROTATION: segmentSize means the number of segments */ if( ri!enablePadding, /* WITH PADDING: Adds type casted NULL values to the last segment to fill up to the size of the segment */ a!forEach( items: enumerate(ri!segmentSize), expression: index( ri!items, 1 /* First item in list is at index 1 and enumerate creates numbers starting at 0 */ + fv!item /* Start number for current segment */ /* Fix segment size */ + enumerate(local!numSegments) * ri!segmentSize, cast(runtimetypeof(ri!items[1]), null) ) ), /* WITHOUT PADDING: Only add left over items into the last segment. The last segment might contain less items */ a!forEach( items: enumerate(ri!segmentSize), expression: reject( a!isNullOrEmpty(_), index( ri!items, 1 /* First item in list is at index 1 and enumerate creates numbers starting at 0 */ + fv!item /* Start number for current segment */ /* Adjust the size of the segment to either the required size or for the last segment the left over items */ + enumerate(local!numSegments) * ri!segmentSize, null ) ) ) ), /* WITHOUT ROTATION: segmentSize means the number of items per segment */ if( ri!enablePadding, /* WITH PADDING: Adds type casted NULL values to the last segment to fill up to the size of the segment */ a!forEach( items: enumerate(local!numSegments), expression: index( ri!items, 1 /* First item in list is at index 1 and enumerate creates numbers starting at 0 */ + (fv!item * ri!segmentSize) /* Start number for current segment */ /* Fixe segment size */ + enumerate(ri!segmentSize), cast(runtimetypeof(ri!items[1]), null) ) ), /* WITHOUT PADDING: Only add left over items into the last segment. The last segment might contain less items */ a!forEach( items: enumerate(local!numSegments), expression: index( ri!items, 1 /* First item in list is at index 1 and enumerate creates numbers starting at 0 */ + (fv!item * ri!segmentSize) /* Start number for current segment */ /* Adjust the size of the segment to either the required size or for the last segment the left over items */ + enumerate(min(ri!segmentSize, count(ri!items) - (fv!item * ri!segmentSize))), null ) ) ) ) ) )