Get the state of a catalog task in the workflow

jack_zheng
Kilo Expert

HI All

I want to create a workflow that will move to the next activity based on the state of the preceding catalog task.   My idea is to use the If activity in the workflow to get the state of the catalog task.   If the state is Closed Complete then the workflow will do something different if it was Closed Incomplete.  

How do I write the script for the If activity to get the state of the catalog task that precedes it?

Thanks

1 ACCEPTED SOLUTION

I found the answer after reviewing the scratchpad wiki:   Using the Workflow Scratchpad - ServiceNow Wiki


2.3.1 Forwarding a Single-Row GlideRecord Object



I added this line to the advanced script of the catalog task activity:   workflow.scratchpad.sc_task_id = task.sys_id;



Then I use the following to access the state in my run script:



var gr = new GlideRecord('sc_task');


      gr.get(workflow.scratchpad.sc_task_id);


View solution in original post

3 REPLIES 3

Alikutty A
Tera Sage

Hi Jack,



You can try this script out and let me know if it worked



answer = ifScript();



function ifScript() {


var task = new GlideRecord('sc_task');


task.addEncodedQuery('active=true^request_item='+current.sys_id);


task.query();


if(task.next() && task.state == 3){


  return 'yes';


}else{


  return 'no';


}


}




Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Is there a way to identify the specific previous activity such as in the following Run Script, it can get the state of the Catalog Task that was created as the previous activity?


find_real_file.png



The script above looks for all tasks related to the RITM with a specific state.   I need to look for the specific previous activity assuming there could be other tasks created as part of the RITM workflow.


I found the answer after reviewing the scratchpad wiki:   Using the Workflow Scratchpad - ServiceNow Wiki


2.3.1 Forwarding a Single-Row GlideRecord Object



I added this line to the advanced script of the catalog task activity:   workflow.scratchpad.sc_task_id = task.sys_id;



Then I use the following to access the state in my run script:



var gr = new GlideRecord('sc_task');


      gr.get(workflow.scratchpad.sc_task_id);