
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 12:52 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 01:06 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 01:06 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 07:00 AM
Thanks Dylan