- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 12:56 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 12:10 PM
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");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 09:47 AM
Looking at your screenshots I see your run script is basically the code I provided. "wf.sys_id" needs to be the SysID of the workflow you want to continue. So if your run script only contains the "wf.sys_id" isn't evaluating. You need to have additional script to look up the workflow context for the request item that you need to continue.
If this doesn't make sense then please provide more detail on what your workflows are doing and how they all tie together. Making an assumption you have multiple sc_req_items on a single request and you are trying to serialize them. if so please provide more detail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 10:16 AM
Thanks for the reply.
I am taking WF A to trigger two WFs while they wait for WF A to complete. The goal is to make sure that WF A task is completed prior to the WF 1 task starts. Right now, all the tasks are started upon submission since all WFs start at the same time.
I tried the other script provided by Vlad but that didn't appear to work either. I'm pretty sure I'm not doing something correctly.
I also tried Chuck's approach and created a script include based on Trigger Workflow Events and added "u_fireWorkflowEvent('workflow.lmscomplete');" to the parent workflow. Still didn't work.
Hope this explains what I'm trying to accomplish.
Here is the "parent" workflow that triggers the event (last activity)
Here's one of the two child workflows (The other is the same other than the task descriptions)
For testing purposes, I make sure the if condition evaluates to yes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 10:44 AM
It is helpful but I am still missing details to further help you. The net of your issue is you aren't broadcasting the event to the right workflow context in your code. In other words your script is yelling "workflow.lmscomplete" but no one can hear you because you haven't directed that yelling at anyone.
As you will see in Chuck's blog there is code that gets all the contexts for a particular record and loops through them all broadcasting the event. Your code isn't doing that so again you aren't directing your event for any of the running flows to hear it.
How are the child workflows getting called? Please provide exact details like a screenshot of that code or activity. We need to figure out how the parent workflow and child workflows are linked together. If you click the Show Workflow related link on your sc_req_item do all 3 show up? If so this means they are all running against the same sc_req_item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 11:49 AM
All 3 WFs are called individually in 3 catalog items from an order guide. They're just checkboxes that initiate the item in one request. Showing workflow only shows one workflow. There's no link between each other than the request.
It makes sense that the event broadcast is not specific. Would it be correct to say that I an additional script is required to find a particular context related to the request and then loop through?
My last attempt used Chuck's code and placed that in a script include.
function u_fireWorkflowEvent(evt) {
var wf = new Workflow().getRunningFlows(current);
while(wf.next()) {
new Workflow().broadcastEvent(wf.sys_id, evt);
}
}
For the "parent" task, I last used the following code to attempt to trigger the event:
u_fireWorkflowEvent('workflow.lmscomplete');
The other two workflows are using the Wait for WF Event activity
There's no additional code being used. Am I using this activity correctly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 12:10 PM
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");
}
}