Arjun_Manchala

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

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.

 

 

 

 

0 Kudos
7 Replies
JonathanT
Apprentice

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

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) )

JonathanT
Apprentice

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

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.

0 Kudos
HP1
Novice

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

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'

 

 

0 Kudos
JohanL
Apprentice

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

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

 


k2_smartforms_nested_if_1546.png
RamKumar
Novice

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

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:

2494iCB5D0771609A73FC.png

 

Any help will be highly appreciated.

 

Regards,

Ram

0 Kudos
jaswerl
Novice

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

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?

0 Kudos
JohanL
Apprentice

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

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

0 Kudos