How to hide options from a lookup select box field type , based on logged in user roles on Record Porudcer

Community Alums
Not applicable

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.

 

5 REPLIES 5

SumanthDosapati
Mega Sage
Mega Sage

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

 

@gaurav tygai 

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

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@gaurav tygai 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader