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
10 replies
Subscribers
8 subscribers
Views
7728 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Single vs Multiple output from IF expression
ajinkyab277
Certified Lead Developer
over 8 years ago
if(
rule!getEmployeeByEmployeeId(ri!employeeId).employeeTypeId = 1,
rule!getFormDataForEmployee(1,2),
{/*Another code*/}
)
In above expression, I use employee id to get Employee data from database using query rule. and based on employee type I call another rule where I pass some hardcoded value(1,2) for the parameter. Ideally, this expression should return me an array of 2 value but it is returning 1 value only.
However if I test condition independantly rule!getEmployeeByEmployeeId(ri!employeeId).employeeTypeId = 1 this returns me true and rule!getFormDataForEmployee(1,2) returns me array of 2 value
Has anyone faced this issue before?
Thanks
Ajinkya
OriginalPostID-251731
Discussion posts and replies are publicly visible
0
ajinkyab277
Certified Lead Developer
over 8 years ago
After adding index [1] in condition it started working (please refer below expression)
if(
rule!getEmployeeByEmployeeId(ri!employeeId).employeeTypeId[1] = 1,
rule!getFormDataForEmployee(1,2),
{/*Another code*/}
)
But still not sure how output of rule rule!getFormDataForEmployee(1,2) changes base on
rule!getEmployeeByEmployeeId(ri!employeeId).employeeTypeId[1] = 1
rule!getEmployeeByEmployeeId(ri!employeeId).employeeTypeId = 1
As both the expression are returning true
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 8 years ago
Have you checked the type of the return is one an array of booleans and the other a boolean?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
ajinkyab277
Certified Lead Developer
over 8 years ago
to simplify this more
if(
{true()},
rule!getFormDataForEmployee(1,2),
{/*Another code*/}
)
above epression single value and
if(
true(),
rule!getFormDataForEmployee(1,2),
{/*Another code*/}
)
expression returning me array
in both th cases it is evaluating the rule!getFormDataForEmployee(1,2) expression
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 8 years ago
Ok I see what you are seeing now - if(
{true()},
{1,2,3},
2
) -returns 1 wheras
if(
true(),
{1,2,3},
2
)
returns 1;2;3
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 8 years ago
Looks like this is the behaviour of an if if you pass in an array variable that only has a single element in it
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 8 years ago
If you amend the code to if(
{true(),true()},
{1,2,3},
2
)
then it returns 1;2
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 8 years ago
You can cast an array to a single element for if checking to make it work or as you've done use [1]
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
ajinkyab277
Certified Lead Developer
over 8 years ago
ohhh got it. so it returns the value base on the array count of condition expresiion. it would be interesting to see whats it will return if the condition expression retunr {true(),false()}
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 8 years ago
It'll return 2 elements from the true condition
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 8 years ago
@ajinkyab Also, this kind of behavior is already mentioned in the documentation of if() and also some discussions took place a while ago on the similar lines at /search?q=OriginalPostID-146293 and /search?q=OriginalPostID-208632.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel