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?

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

OK cool so there is a linkage between the three, a parent sc_request.



In terms of fulfillment, is there a particular order these must follow: request item 1 before request item 2 before request item 3?   If so you may need to have different WF Event names so each can wait for a specific step.   So if request item 1 has to be completed before request item 2, then in request item 2's workflow you can have a WF Event waiting for "reqitem1_complete" and then in request item 3's workflow you can have a WF Event waiting for "reqitem2_complete" as an example.



So with this said the following code should work for you:


// Get all request items linked to parent request


var reqItem = new GlideRecord("sc_req_item");


reqItem.addQuery("request", current.request);


//Exclude current request item from query


reqItem.addQuery("sys_id", "!=", current.sys_id);


reqItem.query();


while (reqItem.next()) {


      // Get running workflows for the current request item


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


      while(wf.next()) {


              new Workflow().broadcastEvent(wf.sys_id, "ENTER YOUR EVENT NAME HERE");


      }


}


View solution in original post

20 REPLIES 20

Hi Michael,



I have the wait for wf event already registered in the workflow. I'm just having issues firing the event.


I've tried the script with my event name but it still doesn't fire. I have this in a script activity but doesn't seem to resume the other workflow.


This workflow is running on the sc_req_item table. The event is also running on the same table. is this correct or should the event run somewhere else?



find_real_file.png



Triggering WF



find_real_file.png


Can you try to insert into the script following?



fireWorkflowEvent(current,'workflow.Imscomplete');



function fireWorkflowEvent(recordGR, evt) {


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


    while(wf.next()) {


          new Workflow().broadcastEvent(wf.sys_id, evt);


    }


}


Unfortunately, the script doesn't work trigger though it runs without error.


That's strange, it actually does work for us pretty well and we are triggering with that piece of code from a transform map, when we import some data from an integration.



Pity is that I cannot find where the events for workflows are logged, they are unfortunatelly not part of the event log table and I cannot find them neither on the wf_activity table...



Can you maybe try to simplify the scenario in the workflow and really make sure that it is the event triggering part and not something else ...


Is it possible my setup is incorrect?



I have an order guide that creates two optional RITMs if they're checked. One (let's call it A) is the workflow that can generate a triggering event. The other two (1 & 2) are the workflows that would be triggered by A.



Workflow A would only trigger 1 and/or 2 if they're related to a particular request and should not trigger any other workflow activities that are unrelated. I'm not sure if that's the normal action.



Right now, if I test it out, if WF A is completed, WF 1 and/or 2 still continue to wait.



Is this the correct or "normal" way Wait for WF event should be used?