Trigger event for Wait For WF Event within workflow

KB15
Giga Guru

I've been looking through any threads for Wait For WF event triggering but I don't seem to get or see how to script this out properly.

I have two workflows that wait for the "workflow.lmscomplete" event

I have script in another workflow to trigger the event"

new Workflow().broadcastEvent(context.sys_id, workflow.lmscomplete);

What am I missing?

Vladimir Kobeti
Giga Guru

Hi,



cannot this article help you?


Trigger Workflow Events v2.0



Or if you want the code directly, could this work for you:


  1. fireWorkflowEvent(current,'my.event.name');
  2. function fireWorkflowEvent(recordGR, evt) {
  3.     var wf = new Workflow().getRunningFlows(recordGR);
  4.     while(wf.next()) {
  5.           new Workflow().broadcastEvent(wf.sys_id, evt);
  6.     }
  7. }


Hope this helps,


Vladimir


I read that article as well but doesn't that article refer to a customization?



The code you're referring to, isn't that a custom function? I've seen it in other threads. If so, why would I need to write a custom function to fire an event? Just a question and not an argument.


And yes you are right, that is a customization, that should help you configure the workflow without need of writing own script, but the script I provided to you should do the "magic" as well 😉


Michael Ritchie
ServiceNow Employee

In your workflow activity you enter the "keyword" you want your workflow to wait on.   It can be anything you want.   Then in your script you will use the code you mentioned in the original post, but the second parameter needs to match the keyword you set in your workflow activity.



So for example, here is the activity that is waiting for a "pulled_scripts" broadcast event:


find_real_file.png



Then to get the workflow going again the following will make it continue:


new Workflow().broadcastEvent(wf.sys_id, "pulled_scripts");



Please mark any posts useful or the correct answer to your question.