Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to check the requested for has ITIL role or not

Mohana Rangan R
Mega Contributor

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 🙂 

4 REPLIES 4

asifnoor
Kilo Patron

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

Jahnavi7
Mega Contributor

Hi @Mohana Rangan R

Did you find the solution for your question?

If yes,can you helpme?

Al-JhonV
Kilo Sage

@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

}