- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 12:52 PM
We have the Service field on our incident form. One of the services in the table is "SAP". I want to restrict the selection of SAP as a business service in an incident to only those users that have the role "sap_authorized_user" (this is a new role we are creating).
How do I filter the values in the Service field so that SAP cannot be chosen if the user doesn't have the specified role.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 11:23 AM
Finalized the working script.
var getSAPService = Class.create();
getSAPService.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkroleof: function(openbyis) {
var servicesare = '';
var reqbyuseris = gs.getUserID();
var rolenameis = 'sap_authorized_user';
var chkuserrole = new GlideRecord('sys_user_has_role');
chkuserrole.addQuery('user', reqbyuseris);
chkuserrole.addQuery('role.name', 'sap_authorized_user');
chkuserrole.query();
if (chkuserrole.next()) {
servicesare = 'nameLIKEsap^ORnameANYTHING';
}
else {
servicesare = 'nameNOT LIKEsap';
}
return servicesare;
},
type: 'getSAPService'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 01:11 PM
Depending on what other reference qualifiers you have you would need to pass if the user has the role and change the query string accordingly.
Another way of doing this would be through a before business rule. An example of this is found on the Incident table with the Business Rule: incident query

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 01:12 PM
Hi Robin,
Quick check that User who should have access to SAP service would be the logged in User or some other User (Reported for/Requested for) from the Incident form.
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 01:46 PM
Only if the current user has the role

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 02:09 PM
Thanks for the clarification. You need to do something as below.
1. Right click Business Service field >> Configure. Then scroll down look for Dictionary override tab & look for incident entry. If not create a new entry under Dictionary Override related list with the Business Service field with Override Reference Qualifer as true & Reference Qualifer as
javascript: new getSAPService().checkroleof(current.opened_by);
2. Script include as below.
var getSAPService = Class.create();
getSAPService.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkroleof: function(openedbyis)
{
var servicesare='';
var reqbyuseris = openedbyis;
var rolenameis='sap_authorized_user';
var chkuserrole=new GlideRecord('sys_user_has_role');
chkuserrole.addQuery('user',reqbyuseris);
chkuserrole.addQuery('role.name','sap_authorized_user');
chkuserrole.query();
if(chkuserrole.next())
{
var getservices=new GlideRecord('cmdb_ci_service');
getservices.query();
while(getservices.next())
{
servicesare='nameLIKEsap^ORnameANYTHING';
}
}
else
{
servicesare='nameNOT LIKEsap';
}
return servicesare;
},
type: 'getSAPService'
});
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.