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
3 replies
Subscribers
8 subscribers
Views
2422 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
I was exploring more on the simple if() function. Ideally the function is writte
georgej
over 9 years ago
I was exploring more on the simple if() function. Ideally the function is written with three parameters
for e.g:- if(condtion,valueiftrue,valueiffalse), but to my surprise I found that following expression is also legitimate
fn!if( false(), true(), false(), 1, 2, 1, 2) and this will return 1 ; also I found if() can accept any number of parameters provided the number of parameters is odd. Can somebody throw more insight into these nuances of if() function. Are there any other interesting functions which can be made very powerful lik this.
OriginalPostID-150245
OriginalPostID-150245
Discussion posts and replies are publicly visible
Parents
0
khalidk912
over 9 years ago
Hello George, this looks like an anomaly but it isn't. Below are few points to elaborate:
1. fn!if accepts an odd number of parameters greater than 3.
2. Condition need not be an equation (a>2) or if condition (isnull). Integer or text can also be provided in the place of condition. when integer is given as condition it returns 'valueIfTrue' and when text is given it returns 'valueIfFalse'. Eg. if(132, "a", "b") returns "a"; if("abc", "a", "b") returns b.
3. The exception to above rule is when you give condition like true, false, true(), false(), 1, and 0 (1 or 0 is translated as true or false respectively when Appian expects Boolean value)
4. When more than 3 odd number parameters are passed it converts your if condition into nested if. With brackets your expression looks like this.
fn!if( false(), true(), if(false(), 1, if(2, 1, 2)))
According to our rule described in point 2, your expression correctly returns second last parameter '1'. Try to change that parameter to "a" and test again. It would return "a".
Hope this puts some light and clarifies any doubt.
-Khalid Khan
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Reply
0
khalidk912
over 9 years ago
Hello George, this looks like an anomaly but it isn't. Below are few points to elaborate:
1. fn!if accepts an odd number of parameters greater than 3.
2. Condition need not be an equation (a>2) or if condition (isnull). Integer or text can also be provided in the place of condition. when integer is given as condition it returns 'valueIfTrue' and when text is given it returns 'valueIfFalse'. Eg. if(132, "a", "b") returns "a"; if("abc", "a", "b") returns b.
3. The exception to above rule is when you give condition like true, false, true(), false(), 1, and 0 (1 or 0 is translated as true or false respectively when Appian expects Boolean value)
4. When more than 3 odd number parameters are passed it converts your if condition into nested if. With brackets your expression looks like this.
fn!if( false(), true(), if(false(), 1, if(2, 1, 2)))
According to our rule described in point 2, your expression correctly returns second last parameter '1'. Try to change that parameter to "a" and test again. It would return "a".
Hope this puts some light and clarifies any doubt.
-Khalid Khan
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Children
No Data