How to write Nested-if conditions in K2 smartforms (Column level Expressions)

  • 9 September 2014
  • 7 replies
  • 210 views

Hi,

 

i need to build up an expression on one of the columns using multiple if conditions. Can anyone let me know how i can perform this in K2 smartforms UI (column level expressions.)

 

i need to perform following logic expressions, in k2 UI.

 

IF (condition1=True)

     Print 'Banana'

else if (condition2=True)

    Print 'Mango'

else

   Print 'Apple'

 

 

In present version, i can able to perform till only one level.

IF (condition1=True),     Print 'Banana',   Print 'Mango'

 

 

Please suggest me any workarounds.

 

 

 

 


7 replies

Userlevel 3
Badge +10

It looks like you just need to nest the second IF in the first IF's failure clause. It's functionally the same as an ELSE IF, with the nested IF's failure clause being equivalent to the overall ELSE.  I.E:


 


Pseudocode:


if (condition1) {


      Banana


}


else {


      if (condition2) {


             Mango


      }


      else {


              Apple


      }


}



SmartForms:
If (condition1, Banana, If (condition2, Mango, Apple) )

Userlevel 3
Badge +10

Another note: Sometimes SmartForms gets fussy when nesting methods in the expression editor (the opening and closing parentheses get messed up somehow) and the only way I've been able to fix the expression is to "Clear All" and carefully re-nest everything.

Badge +1

Hi,

 

I'm using the logical operator (&) for handling mulitple conditions in expression but it doesn't work. Can someone provide me examples for multiple conditions using "&" operator.

 

find the sample below for example:

 

IF (condition1=True & condition2=True)

     Print 'Banana'

else if (condition1=True & condition3 =True)

    Print 'Mango'

else

   Print 'Apple'

 

 

Badge +10

Hi,

 

Nested IFs are possible in an expression, see my screenshot below.

It is a bit complex to set up so an alternative is to create a data label for each condition and then to simply use all of these data labels in a final if expression to display the result.

It is a bit simpler to troubleshoot and very helpful if your conditions change often.

 

Here is an example of using Multiple Data labels to achieve the same:

Data Label 1, type YesNo, Visible = False, Expression:

IF (Condition1 = True & Condition2 = True,True, False)

 

Data Label 2, type YesNo, Visible = False, Expression:

IF (Condition1 = True & Condition3 = True, True, False)

 

Data Label 3, type Text, Visible = True, Expression:

IF (Data Label 1, Banana, IF (Data Label 2, Mango, Apple))

 

Hope this helps!

 

Regards,

JohanL

 


Badge +6

Hi,

I am in the similar kind of need. I have to build an expression to calculate the Total Cost of an item on the basis of selected value from a drop down Region.

The dropdown has two values; UK/CE & India/Tunisia, there is an another field Total Days with number input. The calculation will be:

 

If (Dropdown values is UK/CE, then Total cost = Total Days*100)

If (Dropdown values is India/Tunisia, then Total cost = Total Days*50)

 

Screenshot for better clearity:

 

Any help will be highly appreciated.

 

Regards,

Ram

Badge +5

Hello,

I am in need of a similar solution. is JohanL's solution K2 5.2 capable? in otherwords can it be done in k2 5.2?

Badge +10

Hi,

 

My solution is definitely 5.2 capable, not much has changed with regards to this.

You can also possibly get away with not using DataLabels. 

You can create three expressions without assigning them to a DataLabel and then have your final one doing the final IF assigned to a DataLabel to return the actual result.

 

Hope this helps!

JohanL

Reply