Placing a Timer in a workflow is a good idea or not. Not able to figure it out right now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2019 10:31 AM
Hi All,
I have a workflow on an item where i am checking whether current.requested_for.manager == current.opened_by. If it is Yes it will directly open a task , if it is No it will go for manager approval.
Here is the screenshot of workflow:
Script used in highlighted if condition is as follows:
Current script
// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user');
//gr.get(current.request.requested_for);
gr.addQuery('sys_id',current.request.requested_for);
gr.query();
//if(gr.manager == current.opened_by){
if(gr.next()){
gs.log("hi rav");
var man= current.request.requested_for.manager;
gs.log("Manager is " + man);
if(man == current.opened_by){
return 'yes';
}
}
else{
gs.log("OH Ho");
return 'no';
}
}
Earlier Script
// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user');
gr.get(current.request.requested_for);
if(gr.manager == current.opened_by){
return 'yes';
}
else{
return 'no';
}
}
Anyhow i have to use a 30sec timer as if i don't use timer then it takes requested for same as opened by person.
Can anyone please suggest whether using a timer here is a good idea or bad one.
Regards,
Geet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2019 11:46 AM
Hi a workflow timer is the appropriate/correct way to delay a workflow, but perhaps you need to review your workflow\environment to understand why you are seeing this issue with requested by\opened by and require the delay.
Also note that a 30 second delay will be 30 seconds + processing time,
as the delay is via a sys_event which will be batch processed once the time is reached
and may also be subject to additional delay if the node that picks up the event for processing is busy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2019 09:53 PM
Hi Tony,
I got your point. Actually before that timer i am using a Run Script to update the Request Details. Here is the code.
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', current.request.sys_id);
req.query();
if(req.next()){
req.requested_for = current.variable_pool.u_requested_for_2;
req.opened_by = current.variable_pool.u_opened_by_2;
//req.location = current.variable_pool.u_location;
req.update();
}
current.opened_by = current.variable_pool.u_opened_by_2;
current.requested_for=current.variable_pool.u_requested_for_2;
So, till the time it update the Requested For field, the workflow moves forward to IF condition and if i don't put a timer it never goes to YES answer and always follow the NO node.
Can you suggest something to get out of it!!
Regards,
Geet

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2019 11:50 AM
I agree with Tony. You should introduce a timer if you want to introduce a delay in the workflow but the delay should not be introduced to fix some code.
Instead of writing
return 'yes'; or return 'no'
Write-
answer='yes' or answer='no'
You need to set the answer variable to something because that's what is picked up by the workflow.
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2019 09:53 PM
Hi Priyanka,
I got your point. Actually before that timer i am using a Run Script to update the Request Details. Here is the code.
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', current.request.sys_id);
req.query();
if(req.next()){
req.requested_for = current.variable_pool.u_requested_for_2;
req.opened_by = current.variable_pool.u_opened_by_2;
//req.location = current.variable_pool.u_location;
req.update();
}
current.opened_by = current.variable_pool.u_opened_by_2;
current.requested_for=current.variable_pool.u_requested_for_2;
So, till the time it update the Requested For field, the workflow moves forward to IF condition and if i don't put a timer it never goes to YES answer and always follow the NO node.
Can you suggest something to get out of it!!
Regards,
Geet