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
9 replies
Subscribers
7 subscribers
Views
3545 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Hey all, I'm interested in writing a simple expression rule which will
Mike Schmitt
Certified Lead Developer
over 11 years ago
Hey all,
I'm interested in writing a simple expression rule which will take two arrays (let's say integers, for now), ri!bigArray and ri!smallArray -- and the return will be the indices (if any) of where any members of 'small' are in 'big'. Sort of like a "where" function which can accept multiple targets. I've tried various looping, array, and set functions, and can't quite come up with something which actually works. If anyone has any ideas I'd really appreciate it....
OriginalPostID-69864
OriginalPostID-69864
Discussion posts and replies are publicly visible
0
moritzw
over 11 years ago
I just had the same requirment. I did the following. I create one rule with:
where(ri!array=value,-1) // value being a single value
and another one that is using apply:
=apply(rule!GetIndexOfArrayWithValue,ri!values,ri!array) //values and array are both multiple
not sure wether this is the most efficient way, but I didn't come up with anything better.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike Schmitt
Certified Lead Developer
over 11 years ago
that appears to work, thanks a bunch.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
shelzle
over 11 years ago
Maybe this one
=apply(fn!displayvalue, {1, 5, 12}, {1,3,5,8}, {"one", "three", "five", "eight"}, "no")
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
moritzw
over 11 years ago
Yep. Something like this:
=apply(fn!displayvalue, ri!values, ri!array, enumerate(count(ri!array))+1, "no")
would also work. Not sure which solution is better performance wise.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
subhankarb
over 11 years ago
Can also go for wherecontains(ri!smallArray,ri!bigArray). it is not an documented function. So you will not be able to search in appin expression editor. But using the function in exp editor will give you the desired output.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
moritzw
over 11 years ago
That's definetely the nicest approach.
I guess though that it's possible that non documented functions can get deprecated in any release, right? Or are there maybe any other risks in using undocumented functions?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Owen Parrish
Appian Employee
over 11 years ago
In 6.7 and greater there is a where() function:
forum.appian.com/.../Array_Functions
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike Schmitt
Certified Lead Developer
over 11 years ago
where() doesn't have a way to replicate the functionality I was originally asking about, though (the ability to find the "where" indexes of multiple objects within an array). wherecontains() certainly does, thanks to subhankarb for mentioning that.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Owen Parrish
Appian Employee
over 11 years ago
I would discourage the use of undocumented functions.
Instead, you could use reduce() and 2 expression rules to achieve the desired result:
Rule 1
--------
Name: appendIndexIfContains
Inputs: indices (Integer, Multiple), bigArrayValue (Integer), bigArrayIndex (Integer), smallArray (Integer, Multiple)
Expression: =if(contains(ri!smallArray,bigArrayValue),append(ri!indices,ri!bigArrayIndex),ri!indices)
Rule 2
--------
Name: getIndicesWhereBigContainsSmall
Inputs: bigArray (Integer, Multiple), smallArray (Integer, Multiple)
Expression: =reduce(rule!appendIndexIfContains, {},merge(ri!bigArray,enumerate(length(ri!bigArray))+1),ri!smallArray)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel