Placing a Timer in a workflow is a good idea or not. Not able to figure it out right now.

geet
Tera Guru

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:

find_real_file.png

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

7 REPLIES 7

Hi Priyanka,

 

I tried your suggestion as follows but this also didn't work.

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';
				answer = 'yes';
			}
		}
		else{
			gs.log("OH Ho");
			// return 'no';
			answer = 'no';
		}
}

 

find_real_file.png

 

can you suggest something else.

 

Regards,

Geet

How about you put a Wait For condition after you update the Requested For field. You can check if your current.requested_for field got updated before you start with your If block.

geet
Tera Guru

Hi All,

 

I removed timer and my workflow looks as follows:

find_real_file.png

 

And in IF condition i am using below code now.

find_real_file.png