- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 09:58 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 02:24 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 10:03 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 01:53 PM
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?
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 02:24 PM
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);