Skip to main content
omj2851
January 15, 2025
Question

Invalid index (4) for list: valid range is 1..3

  • January 15, 2025
  • 9 replies
  • 0 views

I have the below mentioned throwing the mismatch error. pls guide

a!forEach(
items: ri!Addresslist,
expression: reduce(
a!update,
fv!item,
merge(
{
"AddressId",
"ReferenceId",
"Type",
"CreateBy",
"CreateDate"
},
{
if(
fv!item.AddressId = ri!primarykey,
null,
fv!item.AddressId
),
ri!Dependent[fv!index].AppianUserId,
"Permanent Home Address",
loggedInUser(),
a!defaultValue(fv!item.CreateDate, now())
}
)
)
)


Expression evaluation error at function a!forEach: Error in a!forEach() expression during iteration 4: Expression evaluation error at function 'merge' parameter 2 [line 14]: Invalid index (4) for list: valid range is 1..3

9 replies

stefanhelzle0001
January 15, 2025

omj2851
omj2851Author
January 15, 2025

a!forEach(
items: ri!Addresslist,
expression: reduce(
a!update,
fv!item,
merge(
{
"AddressId",
"ReferenceId",
"Type",
"CreateBy",
"CreateDate"
},
{
if(
fv!item.AddressId = ri!primarykey,
null,
fv!item.AddressId
),
ri!Dependent[fv!index].AppianUserId,
"Permanent Home Address",
loggedInUser(),
a!defaultValue(fv!item.CreateDate, now())
}
)
)
)

stefanhelzle0001
January 15, 2025

Seems like that your rule inputs AddressList and Dependent are not of the same length.

a!forEach(
  items: ri!Addresslist,
  expression: reduce(
    a!update,
    fv!item,
    merge(
      {
        "AddressId",
        "ReferenceId",
        "Type",
        "CreateBy",
        "CreateDate"
      },
      {
        if(
          fv!item.AddressId = ri!primarykey,
          null,
          fv!item.AddressId
        ),
        ri!Dependent[fv!index].AppianUserId,
        "Permanent Home Address",
        loggedInUser(),
        a!defaultValue(fv!item.CreateDate, now())
      }
    )
  )
)

mikes0011
Brainy
January 15, 2025

Your use of "reduce()" here does not make sense.  What are you hoping to accomplish / why aren't you just using a!update() on its own?

omj2851
omj2851Author
January 15, 2025

I am trying to update the reference_id in table address & from dependent table from of field appianuserid 

mikes0011
Brainy
January 15, 2025

And what purpose is reduce() serving in this?