How to hide options from a lookup select box field type , based on logged in user roles on Record Porudcer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 06:06 AM
So , i have a requirement i need to hide a option on Lookup Select Box Field (we are getting options from a custom table), based on logged in user roles.
For example , if logged in user has admin role , show them 3 fields - X,Y,Z
otherwise show only 2 fields , - X, Y.
How can i achieve this requirement , code would be appriciated.
- Labels:
-
HR Service Delivery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 06:14 AM
Hi,
You need to add reference qualifier to call a script include.
in script include do the required condition check and return the encoded query.
Example :
Reference qualifier :
javascript:new ScriptIncludeName().function_name();
Script include:
function_name : function()
{
if(gs.hasRole('admin')
{
return "sys_idINsysid1,sysid2,sysid3"; //pass the required record's sysid's
}
else if(gs.hasRole('admin')
{
return "sys_idINsysid1,sysid2,sysid3"; //pass the required record's sysid's
}
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 05:03 AM
Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 05:09 AM
Hi,
you can use advanced ref qualifier on that Lookup select box variable
It would look something like this and no script include required
Ensure you give correct sysId of those 3 records in below
Also ensure Lookup value field on that variable is set to SYS ID
javascript: var query; if(gs.hasRole('admin')) query = 'sys_idINsysIdX,sysIdY,sysId3'; else query = 'sys_idINsysIdX,sysIdY'; query;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 11:08 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader