How to debug a workflow script?

praveenKumar2
Kilo Expert

Hi All,

I have written a workflow script and it doesn't seem to work as per the design. 

Requirement : On a catalog request there are several checkboxes which the user chooses and rehire is one of the option. So when the user selects rehire on the catalog and submits the request the workflow is triggered, in the workflow there is a IF condition to validate if the requested for has rehire checkbox as true on his user profile and if yes it has to create a task and if it is no it has to end the workflow. How many ever times i try it always gets the answer as no. Below is the script i have written on the If Condition.

answer = ifScript();
function ifScript() {
var Usr = current.variables.o_employee;
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',Usr);
gr.query();
while(gr.next()){

if (gr.u_rehire == 'true'){
return 'yes';
}
else
{
return 'no';
}
}}

 

Let  me know if someone has a solution to this script.

 

Thanks,

pK.

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

Looks like it should work as long as o_employee is a reference filed.  Try removing the single quotes around true in your if statement.  Also why are doing a while (gr.next()) instead of if (gr.next)?

View solution in original post

5 REPLIES 5

Brian Lancaster
Tera Sage

Looks like it should work as long as o_employee is a reference filed.  Try removing the single quotes around true in your if statement.  Also why are doing a while (gr.next()) instead of if (gr.next)?

Thank you Brian, I knew there was some silly thing i was doing. But thanks for your input 

mm91
Tera Contributor

You may use gs.info in your script to log the messages and remove them when your script work is done.

BTW, script looks ok. can you confirm if o_employee is a reference field ? and if u_rehire is having value as true ?

 

if the above ones are right, see if it returns any values in you script from logs as follows.

 

answer = ifScript();
function ifScript() {
var Usr = current.variables.o_employee;

gs.info("User is "+Usr);
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',Usr);
gr.query();
while(gr.next()){
gs.info("Inside While");

gs.info("User flag is "+gr.u_rehire);
if (gr.u_rehire == 'true'){

gs.info("Inside If");
return 'yes';
}
else
{
return 'no';
}
}

}

 

see what is getting printed and change your code accordingly.

 

thanks!

where to check the info in output?