Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
5 replies
Subscribers
8 subscribers
Views
2846 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
I am having troubles with this bit of code: index( ri!arrayOfCom
mokhtarc970
over 9 years ago
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
0
shailendras593
over 9 years ago
Hi mokhtarc,
Seems that the ri!arrayOfComponent is having a null value and that's why you unable to access its field. Can you try adding a null check like
if(
rule!APN_isBlank(ri!arrayOfComponent),
null,
index(
ri!arrayOfComponent,
wherecontains(
ri!arrayOfProduct[ri!index].id,
ri!arrayOfComponent.FK_productId
),
{}
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
mokhtarc970
over 9 years ago
Great! It worked thanks
but still don't understand what it talks about types in the error...
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
shailendras593
over 9 years ago
@mokhtarc970 glad to know that it worked. Actually, such errors comes when you try to access any field of a CDT type variable that holds a null value. It is good to always have a null check on such variables before accessing their fields.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Aaron Swerdlow-Freed
A Score Level 1
over 9 years ago
Be careful using APN_isBlank here if your array can get very large. The checks it performs can get very costly on larger sets.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
monikar
over 9 years ago
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)
),
{}
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel