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

@Dirk @michael

We have Similar Requirement

 

The Third Party will send the Payload and through scripted Api we have to Query RITM  with the JOB ID and update the Worknotes with the Response code "JOB ID CREATED" or "JOB IF FAILED "  ,Based on that response code we need to move further 

 

**JOB ID will update when Servicenow will Make a Rest Call and post that serviceNow will wait for the Response till that response we need to pause the WORKFLOW 

We have to perform after HTTP STATUS

As i am exposure to the Platform as Nebie