
- 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 12:57 PM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 01:32 PM
I have tried removing else it didn't worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 01:04 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 01:33 PM
Yes, they have values with lower case 'yes' and 'no' and no default value has been set