Skip to main content
October 4, 2022
Solved

using if statements in interface

  • October 4, 2022
  • 15 replies
  • 1 view

Hi all, 

I'm creating an interface that records and calculates the working hours for employees, the idea is if the working hours are less than 8 it should display: " Working hours are incomplete " , and if it was less than 0 it should display: " insert your working hours correctly please " 

I made this expression, but when the value is less than 8 even it was less than 0 it always display : " Working hours are incomplete " 

here's the expression: 

{
a!richTextItem(
if(
ri!WorkingHours = "8",
"Working hours are complete",
if(
8 > ri!WorkingHours > 0,
"Working hours are not complete",
if(
ri!WorkingHours < 0,
"insert working hours correctly please"
)
)
)
)

Best answer by harshitb6843

Multiple conditions in Appian can be configured using or() & and() functions. 

a!richTextDisplayField(
  value: {
    a!richTextItem(
      if(
        ri!WorkingHours = "8",
        "Working hours are complete",
        if(
          and(8 > ri!WorkingHours, ri!WorkingHours > 0),
          "Working hours are not complete",
          if(
            ri!WorkingHours < 0,
            "insert working hours correctly please",
            {}
          )
        )
      )
    )
  }
)

15 replies

harshitb6843
October 4, 2022

Multiple conditions in Appian can be configured using or() & and() functions. 

a!richTextDisplayField(
  value: {
    a!richTextItem(
      if(
        ri!WorkingHours = "8",
        "Working hours are complete",
        if(
          and(8 > ri!WorkingHours, ri!WorkingHours > 0),
          "Working hours are not complete",
          if(
            ri!WorkingHours < 0,
            "insert working hours correctly please",
            {}
          )
        )
      )
    )
  }
)

alim9650Author
October 4, 2022

Thanks for your help, but when I tried the code I got this: Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function 'if' [line 64]: Invalid number of parameters, function 'if' a minimum of 3 parameters (condition,true,false), passed 2.

amans0009
October 4, 2022

try this

a!richTextDisplayField(
  value: {
    a!richTextItem(
      if(
        ri!WorkingHours = "8",
        "Working hours are complete",
        if(
          and(8 > ri!WorkingHours, ri!WorkingHours > 0),
          "Working hours are not complete",
          "insert working hours correctly please"
    
        )
      )
    )
  }
)
 

Participating Frequently
October 4, 2022

Using the amazing match function.

a!richTextDisplayField(
  value: {
    a!richTextItem(
      a!match(
        value: ri!WorkingHours,
        equals: 8,
        then: "Working Hours are complete",
        whenTrue: and(ri!WorkingHours > 0, 8 > ri!WorkingHours),
        then: "Working hours are not complete",
        default: "insert working hours correctly please"
      )
    )
  }
)

alim9650Author
October 4, 2022

it just show the default message even when the user inserts 8, or 4

Participating Frequently
October 4, 2022

workings hours as 8 

working hours as 4