- 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-02-2020 12:31 PM
I must be doing something wrong.
I have over ridden the reference qualifier with the qualifier you provided - javascript: new getSAPService().checkroleof(current.opened_by);
I have created the script include as you specified.
I have 2 users I'm using to test
- Joe Employee (ITIL) - does not have the sap_authorized_user role.
- Joe Employee (SAP) - has the sap_authorized_user role.
When I impersonate Joe Employee (ITIL) and create a new incident, I am still able to select any of the SAP services, as I can when impersonating Joe Employee (SAP).
Was there a part of your sample code that I needed to change for my purposes?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 01:00 PM
I figured it out.
In the variable declaration - var reqbyuseris = openedbyis;
The value openedbyis need to be "current.openedby"
Thanks for your help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 01:05 PM
I don't see where I can select correct.
- 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:47 PM
If possible, I would appreciate some example Java Script that I can work from.
Thanks in advance.