Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Wait For Condition in Workflow not working for state change as cancelled

Pooja58
Kilo Sage

Hi Team,

 

We have a workflow on RITM table.

after a catalog task creation using catalog task activity, I am setting scratchpad object with this task sysID.

in next step I am using wait for condition , using scratchpad value, quering sc_task table and I am checking for state change to cancelled backend value is -10. 

workflow has reached this wait for condition but even after updating the state of task to cancelled still workflow is stuck at wait for condition activity only.

If I check for any other state like closed (backend value is 3). its working fine.

 

Any suggestions team?

bit urgent.

 

Best Regards,

Pooja

 

1 ACCEPTED SOLUTION

The workflow is running on the RITM record, so the Wait for scripts only re-runs every time there is an update to the RITM record.  Closing a Catalog task usually causes a RITM record update.  If it does not in this case, you can try to add a Business Rule to the sc_task table that forces a RITM update when a Catalog Task state changes to Cancelled. 

View solution in original post

14 REPLIES 14

Medi C
Giga Sage
Giga Sage

@Pooja58 

Please share screenshots from your workflow. Wait for condition. and scripts where you are setting scratchpad.


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Hi @Medi C ,
this is the script I m using in wait for condition I did try with backend values instead getDisplayValue, but not working

var taskGr = new GlideRecord('sc_task');
taskGr.get(workflow.scratchpad.sys_id);
status = taskGr.getDisplayValue("state");
gs.info("pooja state "+taskGr.state);
if(status.equals("Cancelled")) {
    gs.info("pooja state inside if"+taskGr.state);
    answer = true;
}

Hello @Pooja58,

 

Is your "status" variable declared? Did you log "workflow.scratchpad.sys_id" to see if it is holding the required value?

Please try:

var taskGr = new GlideRecord('sc_task');
taskGr.get(workflow.scratchpad.sys_id);
var status = taskGr.getValue("state");
gs.info("pooja state " + taskGr.state);
if (status == "YOUR_VALUE") { //Replaced with Cancelled value 
    gs.info("pooja state inside if" + taskGr.state);
    answer = true;
}

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Brad Bowman
Kilo Patron
Kilo Patron

What logs are you seeing with this script?

var taskGr = new GlideRecord('sc_task');
if (taskGr.get(workflow.scratchpad.sys_id)) {
    status = taskGr.getValue("state");
    gs.info("pooja status " + status);
    if (status == -10) {
        gs.info("pooja state inside if " + status);
        answer = true;
    } else {
        gs.info("pooja state else " + status);
    }
}