- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 10:56 AM
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.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 11:04 AM
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)?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 11:04 AM
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)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 11:21 AM
Thank you Brian, I knew there was some silly thing i was doing. But thanks for your input
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 11:23 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 06:26 AM
where to check the info in output?