Show only one option on service field for certain users

BKennedy
Tera Expert

Good day all

 

I have a tricky one

 

on the change form, I have a new field called banking on the drop down(see screenshot directly below), when I am logged in as an ats change user, then only that field should show on the change form. I did like to hide every other option from the dropdown for the ATS users 

 

BKennedy_0-1695911050377.png

BKennedy_1-1695911418310.png

In other words if a regular user, hide banking from dropdown on service field but if an ATS user, show banking as only option 

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hi @BKennedy 

 

It looks like it is a record in referenced table  cmdb_ci_service table.

 

Write reference qualifier on Service field in change form.

 

 

 

javascript&colon;var query = "name!=Banking";  // or may be you can use "sys_id!=<sys if of banking record>"

/*If user is not memeber of that group
if (!gs.getUser().isMemberOf("Group_name")) {
query;
}

 

      else {

          query = "name=Banking";

        }

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Thats the thing, I have an existing reference qualifier

BKennedy_0-1695913210140.png

 

Hi @BKennedy 

 

Can you try by amending the existing query like below

 

 

 

javascript&colon; 
var existingQuery = new global.CMDBCIREIUtils(getBusinessAppsFromService(current.business_service));

var newQuery = existingQuery  + "^name!=Banking"; // or may be you can use "sys_id!=<sys if of banking record>"

/*If user is not memeber of that group */

if (!gs.getUser().isMemberOf("Group_name")) {
newQuery;
}else {
newQuery = existingQuery + "^name=Banking";
}

 

 

VishalBirajdar_0-1695914741973.png

 

This should work without affecting existing reference qualifier.

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Saurav11
Kilo Patron
Kilo Patron

hello,

 

You will have to create a script include and call that from the reference qualifier. In the script include you need to add the condition to return the services based on the user's group.

 

For the script you can refer the below posts:-

 

https://servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-script-i...

https://www.servicenow.com/community/developer-forum/call-script-include-from-reference-qualifier/m-...

 

Please mark my answer as correct based on Impact.