extended if() functionality

Hi,

I'm relatively new to Appian and came across a use of the if() function that didn't seem to fit with the online documentation and syntax. According to some more experienced developers it wasn't unusual, but I was disappointed not being able to figure it out on my own.

How would you all go about understanding a function use that didn't seem to match known syntax? Or help me read the syntax better:

ifcondition, valueIfTrue, valueIfFalse )

showWhen: if(
              local!status = cons!APPL_STS_OFF,
              local!level= cons!APPL_LVL_THIS,
              local!level = cons!APPL_LVL_THAT
            )

  Discussion posts and replies are publicly visible

Parents
  • To explain the syntax of the example expression you've provided...it does conform to the documented pattern - it has a condition, and returns a valueIfTrue and a valueIfFalse.

    Your example is a bit more complex in the that the returned values are themselves not fixed values but are evaluated at runtime. If you took each of the posisble values to be returned and evaluated them in isolation they'd return wither true or false. That is:

    local!level= cons!APPL_LVL_THIS is either true or false

    and

    local!level = cons!APPL_LVL_THAT is either true or false

    ...but only one of them will be evaluated/returned depending on whether local!status = cons!APPL_STS_OFF returns true or false.

    So there's nothing wrong with the syntax of the your if() statement, other than it's hard to read and (probably) hard to debug. The code could have local! variables set to the individual results of those evaluations and used in your if() statement, like this:

    local!isLevelThis: local!level= cons!APPL_LVL_THIS,
    
    local!isLevelThat: local!level= cons!APPL_LVL_THAT,
    
    showWhen: if(
                  local!status = cons!APPL_STS_OFF,
                  local!isLevelThis,
                  local!isLevelThat
                )

    I would find that easier to read/maintain that the example you provided but it is more verbose and does have the (probably immaterial) overhead of evaluating both values when only one is going to be returned.

    By extension you could even code it like this:

    local!isLevelThis: local!level= cons!APPL_LVL_THIS,
    
    local!isLevelThat: local!level= cons!APPL_LVL_THAT,
    
    local!isStatusOff: local!status = cons!APPL_STS_OFF,
    
    showWhen: if(
                  local!isStatusOff,
                  local!isLevelThis,
                  local!isLevelThat
                )

    which is even easier to read and debug imo. I'm sure others will wade in with their opinions...

Reply
  • To explain the syntax of the example expression you've provided...it does conform to the documented pattern - it has a condition, and returns a valueIfTrue and a valueIfFalse.

    Your example is a bit more complex in the that the returned values are themselves not fixed values but are evaluated at runtime. If you took each of the posisble values to be returned and evaluated them in isolation they'd return wither true or false. That is:

    local!level= cons!APPL_LVL_THIS is either true or false

    and

    local!level = cons!APPL_LVL_THAT is either true or false

    ...but only one of them will be evaluated/returned depending on whether local!status = cons!APPL_STS_OFF returns true or false.

    So there's nothing wrong with the syntax of the your if() statement, other than it's hard to read and (probably) hard to debug. The code could have local! variables set to the individual results of those evaluations and used in your if() statement, like this:

    local!isLevelThis: local!level= cons!APPL_LVL_THIS,
    
    local!isLevelThat: local!level= cons!APPL_LVL_THAT,
    
    showWhen: if(
                  local!status = cons!APPL_STS_OFF,
                  local!isLevelThis,
                  local!isLevelThat
                )

    I would find that easier to read/maintain that the example you provided but it is more verbose and does have the (probably immaterial) overhead of evaluating both values when only one is going to be returned.

    By extension you could even code it like this:

    local!isLevelThis: local!level= cons!APPL_LVL_THIS,
    
    local!isLevelThat: local!level= cons!APPL_LVL_THAT,
    
    local!isStatusOff: local!status = cons!APPL_STS_OFF,
    
    showWhen: if(
                  local!isStatusOff,
                  local!isLevelThis,
                  local!isLevelThat
                )

    which is even easier to read and debug imo. I'm sure others will wade in with their opinions...

Children