Only fields with scalar types can be indexed from an array.

Hello

I am facing below issue

I created local called

 local!gridDataStructure: 'type!{urn:com:appian:types}CDT'(

role:{1,2,3}

.

.

.

.

.

)

role is type of list of integer

When i try to print as  local!gridDataStructure.role it throwing an error as

a!gridLayout [line 1068]: Cannot index "role" because it is an array type (List of Number (Integer)). Only fields with scalar types can be indexed from an array.

I tried applying hard coded index([1]) still it's giving a same error.

Please suggest the solution

  Discussion posts and replies are publicly visible

Parents
  • Usually this happens if you have an array of arrays. Is it possible that local!gridDataStructure also contains an array of CDT? Here's an example: 

    a!localVariables(
      local!test: {
        'type!{urn:com:appian:types:PDL}PDL_TestNestedCDT'(
          list:{1,2,3}
        ),
        'type!{urn:com:appian:types:PDL}PDL_TestNestedCDT'(
          list: {4,5,6}
        )
      },
      index(index(local!test, 1, {}), "list")
    )

    This will work because I first index into the first item of "PDL_TestNestedCDT", then index into "list". However, it wouldn't be possible to directly enter local!test.list because that results in a list of lists.

    If you need to display or perform a calculation with this, you can also get around this by using a!forEach() like this: 

    a!localVariables(
      local!test: {
        'type!{urn:com:appian:types:PDL}PDL_TestNestedCDT'(
          list:{1,2,3}
        ),
        'type!{urn:com:appian:types:PDL}PDL_TestNestedCDT'(
          list: {4,5,6}
        )
      },
      a!forEach(
        items: local!test,
        expression: fv!item.list
      )
    )

  • Hey Peter,
     I am able to print by using this

     index(index(local!test, 1, {}), "list")

    But i am facing difficulties in writing because

    I can write to it like  local!test[1].list

    Can you suggest something?

Reply Children
  • You might need to do something with a!forEach() and update just the value of interest. For example, suppose I want to update the list for the second item - here's an expression that might work:

    a!localVariables(
      local!test: {
        'type!{urn:com:appian:types:PDL}PDL_TestNestedCDT'(
          list:{1,2,3}
        ),
        'type!{urn:com:appian:types:PDL}PDL_TestNestedCDT'(
          list: {4,5,6}
        )
      },
      {
        a!richTextDisplayField(
          value: tostring(local!test)
        ),
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              label: "Test",
              saveInto: a!save(
                target: local!test,
                value: a!forEach(
                  items: local!test,
                  expression: if(
                    fv!index = 2 /* only update row 2 */,
                    'type!{urn:com:appian:types:PDL}PDL_TestNestedCDT'(
                      list: {7,8,9}
                    ),
                    fv!item
                  )
                )
              )
            )
          }
        )
      }
    )