The CreatorCon Call for Content is officially open! Get started here.

Chuck Tomasi
Tera Patron

find_real_file.pngOnce upon a time I found a workflow activity called Waitfor WF Event and I thought, "Great, now I can have my workflow pause and if someone clicks a UI action, or a business rule meets certain conditions, I can use gs.eventQueue() to tell the workflow it's time to move on." Unfortunately, it didn't work and that's when I learned that there were two different types of events and how to make that workflow advance when I wanted it to for greater process control.


I believe this has been asked once or twice in the forums so I thought I'd post it here. My favorite solution is to create a new script include.

Name: u_fireWorkflowEvent
Active: true:
Client callable: false
Description: Trigger a workflow event when necessary
Script:



function u_fireWorkflowEvent(evt) {

var wf = new Workflow().getRunningFlows(current);

while(wf.next()) {
new Workflow().broadcastEvent(wf.sys_id, evt);
}
}


This is known as an "on demand function". I could have used a global business rule, however I prefer to use script includes for cases like these. They tend to be a little more "server friendly" since they aren't loaded unless they are called upon.

So let's say I've got a workflow that is waiting for event "request.item.advance". Perhaps this workflow is waiting for another dependent request to complete, or a form button to be clicked, or a business rule to run a certain set of conditions happen. I simply insert a line of code in the workflow script activity, UI action script, or business rule that looks like this:



u_fireWorkflowEvent('request.item.advance');


and the workflow with the Waitfor WF Event activity will advance to the next step. It's like a remote control for your workflow. Remember, the workflow, the UI action, the business rule, or whatever are all going to be operating on the same "current" object. This particular version doesn't allow a separate change request to respond to a WF event. If you're clever, you can adapt the script above to pass a GlideRecord argument and use it, instead of current.

4 Comments