Sub-process input variable: Cannot index from an array using tp[instanceIndex]

Hi everyone, I'm having this issue where I'm trying to index a date and time array using the index of caseID from another array with same order. Below are the process variables and the code that I wrote:

allCases Number (Integer) 3,061,158; 3,061,157; 3,061,156; 3,061,155; 30,611,111; 306,115,555

updatedDateTime Date and Time 20 May 2023 12:00; 21 May 2023 12:00; 20 Jun 2023 12:00; 6 Dec 2023 12:00; 20 May 2023 12:00; 20 May 2023 12:00

However there was no updatedDateTime value passed into my sub-process, so I'm wondering what did I do wrong with the indexing.

Any idea? Thanks a lot in advance :)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I second Stefan's suggested approach.  Add a single script task node right before your subprocess call, and have it output to a new PV of type Array of Map.

    The script task would have a single output entry wherein you reassemble essentially the same code you were trying to pass directly into your subprocess inputs:

    a!forEach(
      pv!casesWithTask,
      
      a!map(
        caseId: fv!item,
        updatedTime: index(
          pv!updatedDateTime,
          whereContains(
            fv!item,
            pv!allCases
          ),
          now()
        )
      )
    )

    You would then hopefully have a PV set to the proper value(s) for your input array, which you can verify the correct values of.  And then for your subprocess inputs, you'd simply set the MNI to reference your new Map PV, and the inputs would be pv!myNewMap[tp!instanceIndex].caseId, and pv!myNewMap[tp!instanceIndex].updatedTime.

    Also (and somewhat confusingly), you might not even need the tp!instanceIndex reference when referring to the specific PV set as the MNI identifier - Appian seems to use some sort of fuzzy logic to automatically pull the "current index" at least when not otherwise overridden.  I haven't tested this extensively recently but it seems to somehow work both ways in some instances.  If anyone knows in any more detail how this works exactly, I wouldn't mind a better description myself, hah.

Reply
  • 0
    Certified Lead Developer

    I second Stefan's suggested approach.  Add a single script task node right before your subprocess call, and have it output to a new PV of type Array of Map.

    The script task would have a single output entry wherein you reassemble essentially the same code you were trying to pass directly into your subprocess inputs:

    a!forEach(
      pv!casesWithTask,
      
      a!map(
        caseId: fv!item,
        updatedTime: index(
          pv!updatedDateTime,
          whereContains(
            fv!item,
            pv!allCases
          ),
          now()
        )
      )
    )

    You would then hopefully have a PV set to the proper value(s) for your input array, which you can verify the correct values of.  And then for your subprocess inputs, you'd simply set the MNI to reference your new Map PV, and the inputs would be pv!myNewMap[tp!instanceIndex].caseId, and pv!myNewMap[tp!instanceIndex].updatedTime.

    Also (and somewhat confusingly), you might not even need the tp!instanceIndex reference when referring to the specific PV set as the MNI identifier - Appian seems to use some sort of fuzzy logic to automatically pull the "current index" at least when not otherwise overridden.  I haven't tested this extensively recently but it seems to somehow work both ways in some instances.  If anyone knows in any more detail how this works exactly, I wouldn't mind a better description myself, hah.

Children
No Data