Appian says I have a List of Text with 2 items, but when I try to get its length it says it has only 1 item.
I need to do a flatten here to achieve the right response with 2 items and its type is not even a List of List of Text.
Code for reference:
a!localVariables( local!test: index({ code: { "A", "B" } }, "code", null), length(local!test) )
Am I doing something wrong here ? I'm really not getting it :/
For me seems Appian is interpreting the type wrong here because of its dynamic typing and even if it says the list has 2 items on the local variables, the interpreter is doing something different.
From time to time we are facing little consistence issues like those and defects are being opened by QA and they take a lot of time for us to find out what the problem really is.
This is something so core to the platform that we assume that it's working, but here and there this kind of stuff keeps hapening.
We are needing to defend ourselfs against the platform because of this kind of stuff, but doing so we create a lot of unecessary overloads for the system.
This really wears us down :/
Really hope I'm doing something wrong here
Discussion posts and replies are publicly visible
I agree, this is an area where Appian can be confusing. The technical issue behind this is that you've got a dictionary, which doesn't enforce types; everything inside a dictionary is of type "Any Type". So the "code" item is a single Any Type object, which contains two things. You can verify this by typename(typeof(local!test)). So the length is technically correct--local!test is a single object--but it's not ultimately what you want. And, of course, the Local Variables section doesn't reflect this, which I agree can be frustrating.
The best fix is to use a!map instead of a dictionary:
local!test: index( a!map( code: {"A", "B"} ), "code", null )
Maps preserve types, so in this case, local!test is properly a List of Text String, and the length is 2.
Thanks for the perfect answer.Do we have a page or any place that has this kind of information ?I really wanted to know this kind of stuff beforehand
It's not spelled out as explicitly as I put it above, but you can reference https://docs.appian.com/suite/help/23.4/parts-of-an-expression.html#dictionaries
Note the "often need to be cast" verbiage and the fact that maps are strongly preferred,
Understood. Thanks for the answer.
Just a sugestion:
I know Appian is a low code platform and meant for everyone to be able to use it to build what they need to.
But I think it's good to explicit this kind of technical information, if possible of couse, because they can help us technicians to guide the team with good practices easier. But I know that this can be confusing for preople without the proper background in programming and computer science. Maybe a more technical section of the documentation suffies this.
But again, thanks for your time helping me, your answer was very very precise and clear.
In my experience these things are not an actual issue most of the time. Appian is pretty good in handling these things. But, if you try to treat it too much like a normal software developer would do, things become more complicated than they have to be. And, yes, there are some very annoying edge cases.