Wait for condition getting cancelled everytime the condition meets

deepika46
Tera Contributor

Hello experts,

 

i Have a workflow and inside that workflow i have a wait for condition activity. Please find the code snippet below:

 

//START

 

// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
var gr_vm = new GlideRecord('u_vm_automation_scheduler');
gr_vm.addQuery('u_requested_item',current.sys_id);
gr_vm.query();
var processed = true;
if(gr_vm.next()){
if(gr_vm.u_status == 'Success' || gr_vm.u_status == 'Error'){
processed = true;
}else{
processed = false;
}
}
 
answer = processed;

//END

 

What is the script doing:

 

We have a table called "u_vm_automation_scheduler" and we have a status field which is originally in "ready" state. In my wait for activity, i am making the workflow to wait untill and unless the status field is Success or Error.(Script above). Whenever the Status becomes Success or Error, the Workflow rather than moving forward, it is getting cancelled everytime. Till the time the status field is  ready , the Wait for condition is waiting but as soon as the condition is meeting for sucess or error the workflow is instantly getting cancelled. Can anyone tell me what i am doing wrong.

 

Thanks in advance.

7 REPLIES 7

Anil Lande
Kilo Patron

Hi,

Why you are using script?

Instead use condition builder and put the condition like below:

Status IS Success <OR> Status is Error

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

The workflow is built in ritm table but i am checking the wait for condition in a different table thats why i am using the script.

Thank you for helping us to understand.

please try the script suggested by @Brad Bowman  , in addition you can initialise answer variable to false in the beginning of your script.

You may check below article to understand how "Wait for Condition" works.

 

For additional info and to know how "wait for condition" works check below article:

 

https://www.servicenow.com/community/developer-articles/how-does-the-wait-for-condition-workflow-act...

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Brad Bowman
Kilo Patron
Kilo Patron

Keep it simple:

var gr_vm = new GlideRecord('u_vm_automation_scheduler');
gr_vm.addQuery('u_requested_item',current.sys_id);
gr_vm.query();
if (gr_vm.next()) {
    if (gr_vm.u_status == 'Success' || gr_vm.u_status == 'Error') {
        answer = true;
}