- 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-24-2016 01:10 PM
Hi,
cannot this article help you?
Or if you want the code directly, could this work for you:
- fireWorkflowEvent(current,'my.event.name');
- function fireWorkflowEvent(recordGR, evt) {
- var wf = new Workflow().getRunningFlows(recordGR);
- while(wf.next()) {
- new Workflow().broadcastEvent(wf.sys_id, evt);
- }
- }
Hope this helps,
Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 01:25 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 02:21 PM
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 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 01:32 PM
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:
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.