Updating Wait for condition in the WF

HenryD
Tera Guru

Hello, I have come across where I want to "stop" the WF in wf editor if a user does not have these two Booleans on the user profile(sys_user) are true at the same time. the wait for condition will check it the first time & if those two fields aren't true, it will stay stuck in the wait for condition which is fine, but later if the user has the required two Booleans = true it does not update the wait for condition and it's just stuck in the workflow & will not proceed. 

 

If both of them are check the WF doesn't start again or rechecks, basically the wait for condition is still stuck even though the condition has been satisfied where both of the Booleans are true. 

 

Has anyone have any tips or something to refer to, I researched some of the restart the workflow or a run script, but I have not had any luck. 

 

I have tried timers and that too but I want it to happen instantly. 

1 REPLY 1

lauri457
Giga Sage

Workflows only follow the transactions on the trigger record. If your wait for condition is scripted and conditional to values on another table you have to explicitly tell the workflow to continue. If wait for condition is waiting for something on current then check that the updates to [sys_user] are not done after calling setWorkflow(false) before the update.

 

For an example on how to continue a workflow you can check the Nudge ui action on [wf_context]:

runWorkflow_forContext();

function runWorkflow_forContext() {
   var contextId = current.sys_id;
	
   if (contextId != null) {
       new Workflow().broadcastEvent(contextId, 'update');
   }
}

 

You should be able to use the execute or update events, see snippet from wait for condition activity handler below:

   onExecute: function() {
      // stay waiting until true or fault
      activity.state = "waiting";
      this.onUpdate();
   },
   
   onUpdate: function() {
      if (this._checkQueryCondition() && this._checkScriptCondition())
         activity.state = "finished";
   },