- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 11:40 AM
I've got a workflow that seems temperamental. Everything is working fine until I get to a "Wait for Condition" where it sometimes works and other times just sits there.
The Wait for Condition is waiting for the task that is generated by the workflow to be assigned, and then it is supposed to allow the workflow to advance. I have a script in the workflow that is checking for the task to be assigned, not sure if this is what's causing it or something else.
var gr = new GlideRecord('sc_task');
gr.addQuery('parent', current.sys_id);
//gr.addQuery('assigned_to', '!=', '');
gr.query();
if (gr.next()){
if (gr.assigned_to != ""){
answer = true;
}
else{
answer = false;
}
}
else{
answer = false;
}
Here is my workflow just for reference:
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 12:42 PM
So, I went and pulled up the BR that's referenced in that runFlows documentation. Looks like there's a new function that handles this now. Here's the script from that BR.
var gr = new GlideRecord(current.parent.getTableName());
gr.addQuery("sys_id",current.parent.toString());
gr.query();
if (gr.next()) {
new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);
}
I think you'll want to use the script in line 5 in your BR instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 12:43 PM
I tossed logs in the BR and its running, the wkfw.runflows(current.request_item, 'update'); is returning the sys_id of the record, that's correct.
I know the wait for condition is working correctly as if I add something to description and save it, it fires the wait for and moves the flow along. I just need to get it to update/run the workflow again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 12:37 PM
One other thing. I believe that function is actually looking for a GlideRecord for the first argument. What you're providing is likely just the sys_id of the record. You may want to instantiate a GlideRecord and get the RITM and pass that in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 12:42 PM
So, I went and pulled up the BR that's referenced in that runFlows documentation. Looks like there's a new function that handles this now. Here's the script from that BR.
var gr = new GlideRecord(current.parent.getTableName());
gr.addQuery("sys_id",current.parent.toString());
gr.query();
if (gr.next()) {
new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);
}
I think you'll want to use the script in line 5 in your BR instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 01:14 PM
Ok got it working -
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id",current.request_item.sys_id);
gr.query();
if (gr.next()) {
new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);
}
})(current, previous);
Thanks a ton for the Help I really appreciate it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 02:09 PM