- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 01:34 PM
Hi Experts!
I have an Issue with an If condition in a workflow.
Here the scenario:
When all the Catalog Task are closed with the 'Close Complete' state, the workflow has to follow the 'Yes' path, and when all the Catalog Task are closed by a different state, the workflow has to follow the 'NO' path.
The IF activity has the next condition.
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
//rec.addQuery('state', '=' ,3);
rec.query();
while(rec.next()){
if (rec.state != 3){
answer = 'no';
}
else if (rec.state == 3){
answer = 'yes';
}
}
The execution of the answer 'NO' works, but when the execution answer is 'YES', both conditions are triggered at the same time.
I hope that you can help me.
Regards
Crhistopher
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 02:25 PM
It may not be looping but it is definitely passing through the if condition twice (once from the branch activity and once from the workflow). The answer cannot simultaneously be 'Yes' and 'No' in a scripted condition, so unless you've modified the activity's transition conditions the highlighting you are seeing is from the two separate evaluations.
So the issue may be less related to the scripting and more to the workflow structure. If you intend for it to be evaluated twice, the highlighting should not really be an issue. It's just a representation of what happened. If it should only pass from one or the other, you need to change the structure so that it is mutually exclusive and only 1 branch makes it to the if activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 02:04 PM
Are there any conditions running alongside the code in the if condition?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 02:06 PM
Is your workflow defined on Catalog Task table?
As per your query you are using request_item to query the Catalog Task table. Since it is a reference column to Requested items table, you might have multiple records resulting in you query in the above logic which is causing this.
You should uncomment //rec.addQuery('state', '=' ,3); in your script and modify the if-else conditions to check the rowCounts. Below is a sample of that.
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('state', '!=' ,3);
rec.query();
if (rec.getRowCount() > 0){
answer = 'no';
}
else if (rec.getRowCount() == 0){
answer = 'yes';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 02:37 PM
Hi bsss,
still having the same problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 02:48 PM
ok i would do this a bit differently.
BEFORE your loop define the variable with a value of yes... then set and if to set it to no if it finds a record.
var answer = 'no';
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('state', '!=' ,3);
rec.query();
if(rec.next()){
answer = 'yes';
}