Is there a case statement /function in Appian . or an if ...else if in rules exp

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

  • @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 ..!!!
  • Try the function choose()
  • @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.
  • 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 */
    }
    )
    )
  • 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.
  • @sikhivahans, Good suggestion.
  • 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

 Discussion posts and replies are publicly visible