Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Nested IF Statements

Jump to solution

I have a drop down in my form with 8 selections  The drop down column name is Condition.  I'm trying to use a calculated value to assign a numeric value to each of the 8 selections. 


For example -

Item 1 (1 pt)

Item 2 (2 pts)

Item 3 (3 pts)

etc. . .

I'm using an IF statement to assign the values, but I can't seem to get it built correctly.  Can someone show me the error of my ways?

Here's an example of the IF statement I'm trying to build -

If(Condition=='Item1','1',if(Condition=='Item2,'2'),if(Condition=='Item 3','3','0')))

Labels: (1)
Tags (1)
0 Kudos
2 Replies
Workflow Hero

Re: Nested IF Statements

Jump to solution

The code that you posted has a few problems that would prevent it from running. 


You're missing the closing " ' " at the end of " 'Item2 ". 

Additionally, you're starting the "if" using the lowercase "i" which isn't the NintexRuntime Function way of expressing that. 

Also because you're closing off the statement prematurely with an ending parens ")", there is no 'else' argument so it couldn't actually execute the statement after this one. 

If you wanted to use the provided Nintex Runtime Functions then you'd need to write it out as is follows: 

If(Condition ==='Item1',1, If(Condition === 'Item2', 2, If(Condition === 'Item3', 3, If(Condition === 'Item4',4, If(Condition === 'Item5',5,0)))))


As you can see, it's just a long chain of Ifs and Elses, and at the very end if nothing is true, then we simply return 0. 

I personally hate how this looks, and you'll need to remember that EACH time you see the word "Condition" that is a Reference that you must insert pointing to the Form Control. 


Another way of doing this would be to write it out as more of a pure Javascript way. This is how I'd probably write it in most cases:

// A more easily readable and expandable version that requires fewer Control References
  var valueMap = {
    "Item1": 1,
    "Item2": 2,
    "Item3": 3,
    "Item4": 4,
    "Item5": 5

  return valueMap[conditionValue] || 0;


This way, if I need to add in a new Option to the drop down, I'm only adding to the 'valueMap' object (don't forget your comma if you add a new property!), and anything outside of those properties will return a 0. 


Here are a few shots of both these methods in action (Spoiler: they do the same thing): 




I hope that this helps you along your way! 

0 Kudos
Workflow Hero

Re: Nested IF Statements

Jump to solution

That's exactly what I needed - thank you, thank you, thank you!!!

0 Kudos