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
18 replies
Subscribers
8 subscribers
Views
5743 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Hello everybody, a question about expressions and arrays here. I have
Jin Pheh
Certified Associate Developer
over 10 years ago
Hello everybody, a question about expressions and arrays here.
I have a function that takes an array of users.
I have multiple arrays of users that I want to call my function on after applying a merge (ie: I want to call my function on the first element of each array, then the second of each array, etc etc). However the apply function treats the result of a merge as individual arguments instead of a single array object when calling my expression. Wrapping the _ placeholder in the apply function with curly brackets causes a syntax error as does casting the result of the merge to a user list.
Has anyone dealt with this before and if so how did you resolve it?
OriginalPostID-138030
OriginalPostID-138030
Discussion posts and replies are publicly visible
0
jackm829
A Score Level 3
over 10 years ago
jpheh, consider applying the append function after the merge. To illustrate: apply(fn!tostring, apply(fn!append, merge({"a", "b", "c"}, {1, 2, 3}))) returns: a1, b2, c3. Whereas: apply(fn!tostring, merge({"a", "b", "c"}, {1, 2, 3})) returns: a, b, c. This demonstrates that tostring was being passed an array when we apply the append, but was being passed multiple distinct elements when just using the merge. As you correctly state that "the apply function treats the result of a merge as individual arguments instead of a single array object when calling my expression.", we can use an applied append to combine the merged distinct elements into an array.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sachinr
over 10 years ago
For this, we can simply pass two arrays to append function of Appian before using it in apply. Your expression will be like apply(fn!yourFunction,append(array1,array2)).
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sachinr
over 10 years ago
I think what want is can be achieved by apply(fn!yourFunction,append(megre(array1,array2)))
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Jin Pheh
Certified Associate Developer
over 10 years ago
mschmitt: I'm not sure I follow what you mean by using the property function. It requires design time knowledge of the field name before it will work meaning I'd have to have an object specific version of the function.
joshl: I have an several arrays of user IDs (the number of arrays is dynamic). I need to check if all the userIDs at index X across all arrays are active. Your suggestion of using the append function is a good one however I've already tried it and it still produces the same error - the function is seeing 2 individual arguments instead of 1 array argument.
sachinr: Thanks for the suggestion but as above, I've already tried that and I'm still getting the same error.
While I have already created a work around it is not as generic, useful or portable as I would like. Thanks for all your help everybody but it looks like this is going to be a "doesn't work" issue for the time being.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
jackm829
A Score Level 3
over 10 years ago
jpheh, did you try applying the append, as in my comment above? apply(fn!yourFunction, apply(append(merge(array1,array2)))). My tests show that this will pass in arrays to your function instead of individual arguments.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike Schmitt
Certified Lead Developer
over 10 years ago
Sorry, I assumed you would have some sort of list of potential field names in advance; if the field names are potentially unlimited or arbitrary, then my prior suggestion doesn't work. (The assumption I had been making was that you had, let's say, 4 different CDT types and they all had a specific "user IDs" field and these aren't likely to change much in the future.)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Jin Pheh
Certified Associate Developer
over 10 years ago
Jackm829: Yes, I tried using the append function. Perhaps it has to do with the type in the array but when I test it using userIDs (instead of string) I still receive an error about an incompatible number of parameters.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sachinr
over 10 years ago
Its not a big issue, you just have to convert that userIDs to user by using touser Appian Function. So, final expression will be : apply(rule!yourRule, touser(append(merge(array1,array2))))
I have tested it. It will work fine.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
<