Wait For Condition Activity

jesusemelendezm
Mega Guru

Hi guys,

I created a condition in a workflow to wait for assigned tasks to be complete... however the workflow doesn't advance to the next activity after I have done the change on the task record that would allow the next activity to run.

This is what I have one the code.

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

answer = true;

var gr_tsk = new GlideRecord("change_task");

gr_tsk.addQuery('change_request', current.sys_id);

gr_tsk.addQuery('u_accept_task', '==', 'Yes');

gr_tsk.addQuery('wf_activity', '');

gr_tsk.query();

if (gr_tsk.next()) {

    answer = true;

} else {

    answer = false;

}

Thanks for your support.

1 ACCEPTED SOLUTION

The wait for script could then be something like this:



var gr_tsk = new GlideRecord("change_task");


gr_tsk.addEncodedQuery('state<3^change_request=' + current.sys_id);


// gr_tsk.addQuery('u_accept_task','Yes'); // I'm not sure/clear why you need this


//gr_tsk.addQuery('wf_activity', ''); // neither sure/clear why you need this.


gr_tsk.query();


if (gr_tsk.hasNext()) {


    answer = false; // if there's at least one record open then continue waiting


} else {


    answer = true; // if there's no records found then exit the wait for activity


}



Thanks,


Berny


View solution in original post

26 REPLIES 26

In other words, the following is a complete list of what you need to do:



Have a business rule on change task the one should validate if all the related change tasks of the parent change request are in a closed state (or whichever condition you're actually using ). If that's the case then proceed to do a force update in the change request. (i'm assuming that your workflow is associated to the change request)



The above force update will wake up the workflow for that record and it will evaluate again wait for condition. This time it should then succeed and move to the next activity in the flow.



I hope this helps! Please let me know if you have any further questions.



Thanks,


Berny


If they are using the 'change tasks' related list then change_request field on change task should contain reference of parent change request. Can you verify if that is the case?


Yes, that's the case.


Add this in a update business rule of change task table



forceChangeRequestUpdate();



function forceChangeRequestUpdate() {


    var wf = new Workflow();


    var cr = new GlideRecord("change_request");


    if (cr.get(current.change_request)) {


  wf.runFlows(cr, 'update');


    }


}


After this I can use the activity wait for condition the change request workflow? BTW The manual tasks are more than 1.