I am having troubles with this bit of code: index( ri!arrayOfCom

I am having troubles with this bit of code:
index(
ri!arrayOfComponent,
wherecontains(
ri!arrayOfProduct[ri!index].id,
ri!arrayOfComponent.FK_productId
),
{}
),
It generates an error for which I don't really get the reason
a!applyComponents [line 25]: Invalid index: Cannot index property 'FK_productId' of type Text into type List of Variant

this FK_productId is an Integer type in the arrayComponent CDT so I don't understand why it says it is a text.

I've tryed tointeger and tostring casts to solve with no result
thanks

OriginalPostID-207016

OriginalPostID-207016

  Discussion posts and replies are publicly visible

Parents
  • As mentioned null handling is very important when accessing any fields of a CDT or any type variable.
    But In few cases upon applicability and the requirement it is always better to use index function with default value present to access fields in CDT.

    Ex: In the above code if you want to get the result even when ri!arrayOfComponent is empty then using index function with default value would be more helpful rather than completely skipping the code using null handling.

    index(
    ri!arrayOfComponent,
    wherecontains(
    ri!arrayOfProduct[ri!index].id,
    index(ri!arrayOfComponent, "FK_productId", null)
    ),
    {}
    )
Reply
  • As mentioned null handling is very important when accessing any fields of a CDT or any type variable.
    But In few cases upon applicability and the requirement it is always better to use index function with default value present to access fields in CDT.

    Ex: In the above code if you want to get the result even when ri!arrayOfComponent is empty then using index function with default value would be more helpful rather than completely skipping the code using null handling.

    index(
    ri!arrayOfComponent,
    wherecontains(
    ri!arrayOfProduct[ri!index].id,
    index(ri!arrayOfComponent, "FK_productId", null)
    ),
    {}
    )
Children
No Data