- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 08:27 AM
I am trying to create a IF statement inside a Workflow to see if the request.requested_for is a Internal employee.
Any suggestions?
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 06:47 PM
Hi,
As the others have mentioned, unfortunately you didn't provide much information for us to assist you...but...the code to query a table would look like:
answer = ifScript();
ifScript() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', current.request.requested_for);
gr.addQuery('u_internal_employee', 'true');
gr.query();
if (gr.next()) {
return 'yes';
} else {
return 'no';
}
}
So here you would want to look at replacing "u_internal_employee" with the name of the field on the user record where you are tracking if they are internal or not? I just assumed it was called u_internal_employee and it was a checkbox returning "true" meaning it was checked.
If so, the path out of the if statement activity in your workflow would go out of the yes route or if they weren't, it would go out of the no path.
Or if you're trying to look for a specific role, then:
answer = ifScript();
ifScript() {
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', current.request.requested_for);
gr.addQuery('role', 'sys_id_of_role');
gr.query();
if (gr.next()) {
return 'yes';
} else {
return 'no';
}
}
Where you'd want to replace "sys_id_of_role" with the sys_id of that role.
My code above is merely an example to get you started.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 09:32 AM
Hi
That code works, but only return yes for both report, I tried to add a new query as you mention but still returning yes for both reports. Now the code look like this
answer = ifScript();
function ifScript() {
var reg = new GlideRecord('u_power_bi_azure_lookup');
reg.addQuery('u_report_name', "Portfolio Metrics Report");
reg.addQuery('u_internal_azure_ad_group', '');
reg.query();
if (reg.next()){
return 'yes';
}
else {
return 'no';
}
}
If there's a way to query the table to check if the report column u_report_name has an empty fill under the u_internal_azure_ad_group returning no , but if the report column u_report_name has something it would say YES

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 09:54 AM
Hi,
If any reply, from anyone, thus far has been Helpful, please mark it as such. Time is being spent on this.
Thanks!
You need to ensure that for u_report_name...that that is:
1) The name of the field
2) That it accepts string text like: "Portfolio Metrics Report" and isn't like a reference field or something...
If all the query lines are correct and a record does have an empty u_internal_azure_ad_group then it will return yes or no appropriately.
If it's saying yes to both things, then it sounds like your query (beyond just stating the table) and the ad_group field, isn't being registered.
With GlideRecord, if one of your query lines is messed up, like doesn't make sense, etc. ServiceNow will just skip over it most of the time and not include it.
So again, your query doesn't narrow down to a specific record.
So double-check the field type, the field values, etc. for that report field.
It's very import that you reference the documentation I've given before, because that explains how it all works.
Else..little by little I'm just explaining everything and you aren't fully learning.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!