VMware Cloud Community
Hejahida8
Contributor
Contributor
Jump to solution

Evaluating multiple conditions on an if statement in workflow

Simple one but it's driving me nuts. How can I evaluate multiple conditions as part of a single if statement?

my code looks like this:

if (element.getAttributeWithKey(key).value !=="" || element.getAttributeWithKey(key).value != 0 || element.getAttributeWithKey(key).value != null){

.... rest of workflow script here

}

My values are coming from a configuration element and I basically want to check whether the value of a particular attribute from that configuration element is not empty, zero or null so that I can ignore the attribute in that case.

If I split the if/or statement into three individual if statements one after the other my code works as I want it to do, ignoring attributes with an empty/zero or null value, but when combined into an or statement the workflow doesn't function as expected and doesn't ignore the attributes with an empty/zero or null value.

Can anyone point out where I am going wrong?

I have tried

if ((element.getAttributeWithKey(key).value !=="") || (element.getAttributeWithKey(key).value != 0) || (element.getAttributeWithKey(key).value != null)){

also

if ((element.getAttributeWithKey(key).value) !=="" || (element.getAttributeWithKey(key).value) != 0 || (element.getAttributeWithKey(key).value) != null){

without success.

Shouldn't make a difference but this is in vRO 6.0

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

The problem is that in the if statement you are using disjunction || but you should be using conjunction &&

For the attribute to be considered non-empty, it should satisfy ALL the 3 conditions, not only one of them Smiley Happy

View solution in original post

0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

The problem is that in the if statement you are using disjunction || but you should be using conjunction &&

For the attribute to be considered non-empty, it should satisfy ALL the 3 conditions, not only one of them Smiley Happy

0 Kudos
Hejahida8
Contributor
Contributor
Jump to solution

Perfect! amended my code and as you suggested it correctly identifed and ignored the 0 or empty attributes. Thank you very much, I knew it must be something simple but it didn't occur to me that I needed all three conditions to be true if something was empty, I'll remember that for future use cases Smiley Happy

0 Kudos