I have a process model that includes a script task with the following output:
rule!SC_getImportPregressoPc(id: pv!index)
The problem I'm facing is that I'm incrementing the index by 1 in each iteration to move to the next item, but the IDs in my dataset are not sequential. For example, I have IDs like 5, 6, 7, but the next ID might be 500 due to filtering applied by the rule, causing my process to exit early when it reaches a gap in the ID sequence.
How can I configure the process to iterate over only the IDs present in my filtered list, rather than assuming a simple +1 progression?
Any guidance would be appreciated!
Discussion posts and replies are publicly visible
What I don’t understand is how it doesn’t fail on the very first execution. Since you haven’t shared the code for how startIndex is set, I assume you're initializing it with a value of 1. But given the example IDs you mention (5, 6, 7, 500), you should already be hitting the null condition on the first iteration.
startIndex
null
As others have mentioned, the issue is that you're using index + 1 assuming it matches a record ID, but that's not reliable unless the IDs are sequential and gapless.
index + 1
What you should do instead is replace your expression with something like this:
a!localVariables( local!index: a!defaultValue(ri!index, 1), index( a!queryRecordType( recordType: 'recordType!{yourRecordType}SC Import Pregresso PC', fields: {}, filters: { a!queryFilter( field: 'recordType!{yourRecordType}SC Import Pregresso PC.fields.{yourField}scarto', operator: "=", value: false ) }, pagingInfo: a!pagingInfo( startIndex: local!index, batchSize: 1 ) ).data, 1, null ) )