Wait for Condition trigger by variable on one sctask
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 02:46 PM - edited 12-05-2022 02:57 PM
We have a workflow running on the sc_req_item table. It has several task activities in the workflow, however we have a certain one that the user updates one variable(yes/no) on, we need the wait for condition to wait until that specific variable is updated before proceeding. The issue is the user will not CLOSE COMPLETE the sctask but do a save and exit instead until later in the process. If i close task, the wait for activity works correctly, if I try to save and exit or save and stay, the wait for activity does not work. Here is the script that is in place currently. Is there away to force the update as if I closed the task? I've tried several different scripts and running against sc_task instead as well and this one works when the sctask is closed but not when it's simply saved. I'd like to do this from within the workflow and not use a business rule. I know it can be done with a business rule but I'm trying to avoid that if possible.
var gr = new GlideRecord('sc_req_item');
gr.get(current.sys_id);
gr.query();
while(gr.next()) {
if(gr.variables.upload_agreement_or_contract == 'Yes'){
answer=true;
workflow.info("Answer is - " + gr.variables.upload_agreement_or_contract);
}
else{
answer=false;
workflow.info("Answer is - " + gr.variables.upload_agreement_or_contract);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 03:36 PM
You don't ever need to do a GlideRecord on sc_req_item to retrieve the current record as the workflow is running on the sc_req_item table, and you can simply use the convention current.variables.variable_name... That isn't causing the script to behave any differently, just unnecessary scripting. What you really want to do in this script, or by using the condition builder is wait for the variable to not be empty. The way you have it written now, the wait for will not be satisfied by a 'No' response. If you need to take different actions based on the Yes or No, then follow this with an If activity to do that. So the wait for script would simply be:
if (current.variables.upload_agreement_or_contract != '') {
answer = true;
} else {
answer = false;
}
It sounds like your issue with the timing might be the arrangement of the activities, not the script itself. If this wait for activity comes after the Catalog Task activity, and that activity has the 'wait for completion' box checked, the workflow will not progress until the Catalog Task enters an inactive state. So what you want to do in this scenario is have the wait for run in parallel with this Catalog Task. You can do this simply by adding an arrow from the previous activity to the Wait for rather than it following the Catalog Task, then your If activity (if you need to distinctive paths for 'Yes' and 'No') then the next activity, or a join to wait for the Catalog Task to be closed before proceeding if that's what you want to do.