Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Suggested Answer
+2
person also asked this
people also asked this
Replies
8 replies
Answers
3 answers
Subscribers
10 subscribers
Views
17644 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Is there a case statement /function in Appian . or an if ...else if in rules exp
Dhiraj Kumar
over 8 years ago
Is there a case statement /function in Appian . or an if ...else if in rules expressions . Coding in terms of if , if ... is time consuming and code readability is bad .
OriginalPostID-219960
OriginalPostID-219960
Discussion posts and replies are publicly visible
0
mohammedz
Certified Senior Developer
over 8 years ago
@diraj
As per my knowledge everyone use to have nested if by the way you have used ..
To Make it readability for code u can use rules rather than using plain condition which makes code clumsy.
That's a good question let's see others view on this ..!!!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
aayusha
Certified Senior Developer
over 8 years ago
Try the function choose()
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 8 years ago
@dhirajk Hi, fn!displayvalue() can be an option as well. Though the readability is bad, I would suggest leaving the code as is, because it may not be a great idea to pull the results of the each condition into an separate expression rule, as the expression rule in-turn consumes some time for initialisation, processing and returning the output which ultimately increases the total execution time. Doing so on need basis(for instance, when the conditional output is a frequently changing, or is reusable, or contains a huge piece of code) might be worth rather than just for sake of improving the readability.
An other option is to build a matrix in database but it really depends on the nature of the requirement.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Sowrabha Rajashekar
over 8 years ago
choose() function acts like swich case !
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
+1
chetany
A Score Level 1
over 8 years ago
I would suggest a combination of fn!choose and fn!displayvalue to simulate a "switch" case in Appian. fn!choose is like switch case - but with one caveat - the "key" should be a number - it does not allow text values or float values. So, you can use fn!displayvalue with fn!choose when the value which decides which branch to takes is not a number.
Example Snippet:
load(
/*local!statusCode will be 1 or 2 or -1
1 - Approved
2 - Rejected
-1 - Some invalid value*/
local!statusCode: fn!displayvalue(
ri!status,
{"Approved", "Rejected"},
{1,2},
-1
),
fn!choose(
local!statusCode,
{
/*code for choice1 */
},
{
/*code for choice2 */
}
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel
+1
sikhivahans
over 8 years ago
As long as the rule doesn't return a list, an additional call to fn!choose() isn't required and requirement can be accomplished just by making use of fn!dislayvalue() as follows:
fn!displayvalue(
ri!status,
{
"Approved",
"Rejected"
},
{
rule!myRuleForApprovedStatus(),
rule!myRuleForRejectedStatus()
},
rule!myDefaultRule()
)
In case if the rules returns lists, fn!choose() can be used.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel
0
chetany
A Score Level 1
over 8 years ago
@sikhivahans, Good suggestion.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
+1
amitb0004
over 6 years ago
Hi Dhiraj Kumar,
There is one function "choose( index, choice1, choice2, … )", you can used it as switch case logic...
follow the following link for more details:
docs.appian.com/.../fnc_logical_choose.html
And for if_else
"if(condition,statement1, statement2)"
in above syntax if condition is true "statement1" will get executed else "statement2"
In these way you can used if_else in Appian
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel