How to check the requested for has ITIL role or not

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 06:46 AM
Script include part :
rolecheck: function() {
var a = this.getParameter('sysparm_usr');
var b = new GlideRecord('sys_user_has_role');
b.addQuery('sys_id', a);
b.query();
if (b.next()) {
return b.role;
}
Catalog Client script :
var c = g_form.getValue('requested_for');
var a = new GLideAjax('rolecheckoneamerica');
a.addParam('sysparm_name', 'rolecheck ');
a.addParam('sysparm_usr', c);
alert(c);
a.getXML(apply);
function apply(response) {
alert("in side apply function 🙂 ");
alert(response);
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
No luck any suggestion in the above code 🙂
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 07:01 AM
Can't you just use: g_user.hasRole('itil'); https://docs.servicenow.com/bundle/newyork-application-development/page/app-store/dev_portal/API_ref...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 07:02 AM
Hi,
Try like this. Made 1 change in SI. it has to b checked by user column, not sys_id.
Script include part :
rolecheck: function() {
var a = this.getParameter('sysparm_usr');
var b = new GlideRecord('sys_user_has_role');
b.addQuery('user', a);
b.query();
if (b.next()) {
return b.role;
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2020 07:31 AM
Hi @Mohana Rangan R
Did you find the solution for your question?
If yes,can you helpme?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 09:58 PM
@Mohana Rangan R
Please this idea:
var rfor = g_form.getValue('request.requested_for');
var checkrole = new GlideRecord('sys_user_has_role')
checkrole.addQuery('user.sys_id','=', rfor);
checkrole.addQuery('role.name','STARTSWITH', "itil"); //user that has no itil role
checkrole.query();
while(checkrole.next()){
//your actions here
}