iterate next item in the list

Certified Associate Developer

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

  • 0
    Certified Lead Developer

    What is SC_getImportPregressoPc() doing?

    If it's querying, why wouldn't the "pv!index" you're feeding in just iterate the StartIndex of the PagingInfo?  This would completely bypass the issue of gaps in an ID sequence, and even different sortings (if you want to prioritize items by implementing custom sorts, etc).

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    this is what  my SC_getImportPregressoPc() returns only one value using id filter:

    index(a!queryRecordType(
      recordType: 'recordType!{}SC Import Pregresso PC',
      fields: {},
      filters: a!queryLogicalExpression(
        operator: "AND",
        filters: {
          a!queryFilter(
            field: 'recordType!{}SC Import Pregresso PC.fields.{}scarto',
            operator: "=",
            value: false
          ),
          a!queryFilter(
            field: 'recordType!{}SC Import Pregresso PC.fields.{}id',
            operator: "=",
            value: ri!id
          )
        },
        
       
        
        ignoreFiltersWithEmptyValues: true
      ),
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 100
      )
    ).data,1,null)

    I understand your explanation, but I'm still not sure how this approach helps me iterate through the next item in the list without using id. Could you please provide a more detailed example or breakdown to make this clearer? Thank you!

  • 0
    Certified Lead Developer
    in reply to hamzas0003

    What   is referring to, is using the paging info to fetch one item after the other. 

    https://docs.appian.com/suite/help/25.1/fnc_system_a_paginginfo.html

    When you set the batchSize = 1, and increment the startIndex on each cycle, you do not have to care anymore about the primary key values.

  • 0
    Certified Lead Developer
    in reply to hamzas0003

    What PagingInfo are you passing into your query?

  • +1
    Certified Lead Developer

    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.

    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.

    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
      )
    )