How do I get the wait for condition to look at the Task on an Incident Workflow?

cmoffett
Tera Contributor

I have an Incident workflow that is fired from the creation of an incident with a certain condition.   Once fired it creates 13 tasks that are waiting for acknowledgement you can acknowlede from email sent, the portal or from the record it self.   Once a task is acknowledged I want to resolve it.   So how do I get the wait for condition to look at the task it is attached to and wait for that acknowledgment. If I just look at the field with out a script it looks at the Incident and not the Task, so will need it to look at each task right now I have the 13 tasks and a wait for condition lined up for each of the tasks then a script to update it to resolved.

update:

I've added the below script into the Wait For Condition and it seems to work some times most of the time I have to nudge the work flow in the active context to get it to move past the wait for condition.

// Set the variable 'answer' to true or false to indicate if the condition has been met or not.

//Query for specific task to check if acknowledged

answer = ifScript();  

 

function ifScript() {  

      var inc = new GlideRecord('incident_task');  

      inc.get(workflow.scratchpad.ciops);  

    if (inc.u_acknowledge == true) {  

              return true;  

      } else {  

      return false;  

}  

}

1 ACCEPTED SOLUTION

Yes, you are correct. Since we are wanting to update the incident record, we need to get the record object first before we can update it. I have modified your code accordingly:



(function executeRule(current, previous /*null when async*/) {


      var incObj = new GlideRecord('incident');


      if (incObj.get(current.incident)) {


              incObj.work_notes = 'Incident Task Acknowledged, task state Set to Closed Complete';


              incObj.update();


      }


})(current, previous);



Let me know if you need further assistance,


View solution in original post

4 REPLIES 4

ccajohnson
Kilo Sage

Wait conditions on a workflow will trigger whenever the record the workflow is running against is updated. The Incident record probably is not updated when the Incident Task is acknowledged, so it will continue to wait. What I have done to get around this is to have an onAfter Business Rule running on the Incident Task table that will update the work notes on the Incident indicating the Incident Task has been acknowledged. Then, because the Work notes on that Incident record are updated, the workflow will trigger the wait condition. The connection between the Incident Task and the Incident OOB is the Incident [incident] field.



Let me know if you still need assistance,


Thank you for your update and reply, I'm fairly new to ServiceNow and my scripting is mediocre at best.   I have the onAfter business Rule set and running to fire when Acknowledged = true and short description is certain verbiage.      



scripting I have in advanced:



(function executeRule(current, previous /*null when async*/) {


current.incident.work_notes = 'Incident Task Acknowledged, task state Set to Closed Complete';


})(current, previous);



I think this is lacking something to get it to update poperley any help you can give is much appreciated.



Thank you.


Yes, you are correct. Since we are wanting to update the incident record, we need to get the record object first before we can update it. I have modified your code accordingly:



(function executeRule(current, previous /*null when async*/) {


      var incObj = new GlideRecord('incident');


      if (incObj.get(current.incident)) {


              incObj.work_notes = 'Incident Task Acknowledged, task state Set to Closed Complete';


              incObj.update();


      }


})(current, previous);



Let me know if you need further assistance,


What Chris wrote is true - you are probably not updating the incident on which the workflow runs after every task is closed. In that case, the wait for condition activity will not check for the condition again. You can use a function setForceUpdate(true) to update a record even without changing any field value.



The above BR is not correct (assuming it runs on your task table). You cannot update a record from another table in the same way you dot-walk to grab the field values. You need to use GlideRecord:



var gr = new GlideRecord('incident');


if(gr.get(current.incident.toString()) {


        gr.setForceUpdate(true);


        gr.update();


}



Try this and see if it changes anything. if not it might be good to see how your workflow is built. I'm not sure if I understood correctly - do you want to do something with the task itself or the parent incident when a task is resolved? Another idea might be to use the branch/join activities which force the workflow for all branches to complete before progressing.