- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 12:46 PM
I have a workflow that in one step a flag "TAC Needed" is set to true. Two steps later a test is made of that workflow variable. When true the catalog task, "TAC Implementation" is created. In "TAC Implementation" they can change the state to Close Incomplete and rollback the workflow to the step where the "TAC Needed" flag is set. Now the flag is set to false. So now the workflow bypasses the "TAC Implementation" step as it is not needed and continues on until the workflow finishes. "TAC Implementation" step is left with a "Pending" state. I want to insert a Run Script step after the step where the flag is set. If the flag is false and if the "TAC Implementation" step exists than change its state to "Closed Skipped".
My approach is to capture the sys_id of the "TAC Implementation" catalog task to a workflow sandbox variable so after the rollback I can use a glide record on the sc_task and set the state to "Closed Skipped"
I have tried to capture the sys_id of the "TAC Implementation" catalog task in the "TAC Implementation" catalog task's step's advanced script. I have used workflow.scratchpad.taskid = task.setNewGuid();and workflow.scratchpad.task_id = task.sys_id; but the workflow.scratchpad.task_id always end up undefined.
Is there a better overall approach. When can I capture the sys_id of a catalog task?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 03:32 PM
I assume your workflow is running on a request item.
What you could do is to make a glide record query for all related catalog tasks to the RITM and add a query to filter out the TAC Implementation task. Don't know what this task looks like but I assume you have some value on this task that will identify it as a TAC Implementation task.
Whit this info you can sort out these tasks and then update them to have state closed incomplete.
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('INSERT FIELD TO VERIFY TAC TASK', 'VALUE OF THIS FIELD');
gr.addQuery('state', 'VALUE OF CLOSE INCOMPLETE STATE');
gr.addQuery('u_tag_needed', 'false');
gr.query();
while(gr.next()){
gr.setValue('state', 'VALUE OF CLOSE SKIPPED STATE');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.updaet();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 03:32 PM
I assume your workflow is running on a request item.
What you could do is to make a glide record query for all related catalog tasks to the RITM and add a query to filter out the TAC Implementation task. Don't know what this task looks like but I assume you have some value on this task that will identify it as a TAC Implementation task.
Whit this info you can sort out these tasks and then update them to have state closed incomplete.
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('INSERT FIELD TO VERIFY TAC TASK', 'VALUE OF THIS FIELD');
gr.addQuery('state', 'VALUE OF CLOSE INCOMPLETE STATE');
gr.addQuery('u_tag_needed', 'false');
gr.query();
while(gr.next()){
gr.setValue('state', 'VALUE OF CLOSE SKIPPED STATE');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.updaet();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2018 11:33 AM
I tool palmen's code and adapted it, added some addInfoMessage statements to come up with the final version below:
Thanks palmen.
gs.addInfoMessage("TAC Needed: " + current.variables.voice_ltdmv_tac_needed);
gs.addInfoMessage(" current sc_req_item: " + current.getUniqueValue());
if (current.variables.voice_ltdmv_tac_needed == 'No') {
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('short_description', 'TAC implementation');
gr.addQuery('state', '-5'); //Pending
gr.query();
if (gr.next()){
gs.addInfoMessage("Change state from: " + gr.getValue('state') + " to 7");
gr.setValue('state', '7'); // Close Incomplete
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
} else {
gs.addInfoMessage("No TAC implementation task for: " + current.getUniqueValue());
}
}