Help needed on 'ELSE IF' multiple condition

Devhelp
Kilo Contributor

Hi, I need some help on scripting. I am struck with trying to code using multiple 'Else If' condition in a script. Here is my script let me know if i am missing something.

I am using different combinations for outputs. The results with combinations working fine are lines from 1-4 and 11-13 (if and else part)the middle part is not working.

1.if (requestItem.AP == 'yes' || requestItem.TOM == 'no') {
2.Type = 'In Building';
3.
4. }
5.else if(requestItem.AP == 'yes' || requestItem.TOM == 'yes') {
6.Type = 'Bridged';
7. }
8.else if(requestItem.AP == 'no' || requestItem.variables.TOM == 'no') {
9.Type = 'Out Building';
10 }
11else {
12Type = 'Bridged';
13 }
  Please help me

1 ACCEPTED SOLUTION

Dylan Mann1
Giga Guru

I think you're if, else if structure is fine there is no need to change these all to ifs.

The problem you're facing is because you're using OR conditionals, so only one part of the condition needs to be true for the script to execute. So if requestItem.AP == 'yes' the first condition will always run and the second condition will not even if requestItem.TOM == 'yes'. Try the code snippet below

1.if (requestItem.AP == 'yes' && requestItem.TOM == 'no') {
2.Type = 'In Building';
3.
4. }
5.else if(requestItem.AP == 'yes' && requestItem.TOM == 'yes') {
6.Type = 'Bridged';
7. }
8.else if(requestItem.AP == 'no' && requestItem.variables.TOM == 'no') {
9.Type = 'Out Building';
10 }
11else {
12Type = 'Bridged';
13 }

 This uses the AND conditional (&&), this way both conditions must be true in order for that if block to run its code.

Let me know if this helps,

Dylan

View solution in original post

6 REPLIES 6

Nitin_NOW
Tera Guru

Please try to remove 'else' and only use the 'if' condition and check again. Also not sure how the lines 1-4 and 11-13 are working as they just say for example Type='Bridged' instead of using setValue() or something similar to this. 

Please hit correct based on impact of response.

Thanks!

I have tried removing else it didn't worked

 

Laurie Marlowe1
Kilo Sage

Are the "yes" and "no" choice fields with those labels?  Are the values "yes" and "no" (lower case)?

Does your Type field have a default?

 

Thanks,

Laurie

Yes, they have values with lower case 'yes' and 'no' and no default value has been set