- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 01:36 PM
Using this is an IF check on a workflow, and not sure where I'm going wrong. It's not catching when the field is empty.
var gr = new GlideRecord("sys_user");
gr.get(current.variables.request_for.toString());
gs.warn(gr.u_jobfamily);
if (gr.u_jobfamily == 'SB') {
answer = 'yes';
}
else if (gr.u_jobfamily.nil()) {
answer = 'yes';
}
else {
answer = 'no';
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 02:05 PM
Thanks for the update. However if you feel the issue is still there you can give a try with below script:
answer = ifScript();
function ifScript(){
var gr = new GlideRecord("sys_user");
gr.get(current.variables.request_for.toString());
gs.warn(gr.u_jobfamily);
if (gr.u_jobfamily == 'SB') {
return 'yes';
}
else if (gr.u_jobfamily.nil()) {
return 'yes';
}
else {
return 'no';
}
}
Regards,
Alok

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 01:52 PM
Is there any default value on the field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 01:53 PM
No. no default value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 01:55 PM
Would it be better to do it this way?
var gr = new GlideRecord("sys_user");
gr.get(current.variables.request_for.toString());
gs.warn(gr.u_jobfamily);
answer = 'no';
if (gr.u_jobfamily == 'SB') {
answer = 'yes';
}
if (gr.u_jobfamily.nil()) {
answer = 'yes';
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 01:56 PM
what type of field is u_jobfamily? and is the rest of code working as expected?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 01:56 PM
It's a string value, and yes the rest is working.