Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to find non admin user in service now

Nag9
Tera Expert

How to find non admin user in servicenow, he must have permissions to raise Ritm

1 ACCEPTED SOLUTION

Can you add the log statement  in the script include after this line and tell me the log output.

     var thisUser = gs.getUser().getUserByID(userID);

gs.log("Group name is "+groupName+"----"+userID);

 

View solution in original post

93 REPLIES 93

Hi Asif, Hope you remember our discussion on variables tab restriction.

As of now its working correctly with your modified code.

 

So here me question is

once the task sets to closed complete on ritm form then only variables tab should be in read only mode.

 

Here is the script that we both are worked

 

Script include:

var MyGroups = Class.create();
MyGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isGrpMember:function() {
var userID = this.getParameter('sysparm_userID');
var groupID = this.getParameter('sysparm_groupName');
//get the group name based on the group id
gs.log("Entered the function of isGRP Member");
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id",groupID);
gr.query();
if (gr.next()) {
gs.log("Enered into the if condition of my script include");
var groupName = gr.getValue("name");
var thisUser = gs.getUser().getUserByID(userID);
if (thisUser.isMemberOf(groupName)) {
gs.log("Returned true becuase user is member of this group");
return true;
}
else {
gs.log("Returned false because user is not a member of this group");
return false;
}
} // end of if gr.next
},
type:'MyGroups'
});

 

 

Client script:

 

function onLoad() {
//Type appropriate comment here, and begin script below
var item=g_form.getValue('cat_item');
if (item=='e7d48d55db5f8b00c77b7016bf96199b' || item=='e386bfb3dba68700c77b7016bf961943' || item =='ae244264dbb6c700c77b7016bf961944' || item== '1813429bdb83c700f3e5f156bf9619e9' || item== '0d0c3f5adb28e3001ac0105f6896198e' || item =='f2377d15db9f8b00c77b7016bf96191c' || item=='f477b155db9f8b00c77b7016bf961967')
{
//g_form.addInfoMessage("Entered into if condition");
var ga = new GlideAjax('MyGroups');
ga.addParam('sysparm_name', 'isGrpMember');
//ga.addParam('sysparm_userID', g_user.userID);
ga.addParam('sysparm_userID', g_user.userName);
ga.addParam('sysparm_groupName',g_form.getValue('assignment_group'));
ga.getXML(hideField);
//g_form.addInfoMessage("Entered into the function" +answer);
}
//g_form.addInfoMessage(g_user.hasRole('admin'));
function hideField (response) {
var answer = response.responseXML.documentElement.getAttribute('answer').toString();
//g_form.addInfoMessage("Entered into the function" +answer);
//g_form.addInfoMessage(g_user.hasRole('admin'));
if ((answer == 'false') && !g_user.hasRole('admin')) {
g_form.setVariablesReadOnly(true);
}
else
{
g_form.setVariablesReadOnly(false);
}

}

}

 

 

Can you help on this 

Hi Nag,

It is recommended that you open a new thread for a new question.

Regarding your question, in the below code jsut add your condition of the state of the RITM.

if ((answer == 'false') && !g_user.hasRole('admin')) {
g_form.setVariablesReadOnly(true);
}
else
{
g_form.setVariablesReadOnly(false);
}

If there is a follow up question, kindly open a new thread.

Mark the comment as helpful if this helps.

Nag9
Tera Expert

Can you elaborate and send me the code

Nag9
Tera Expert

Can you elaborate and send me the code

Replace your if and else condition in client script with the below code.

if ((answer == 'false') && !g_user.hasRole('admin') && g_form.getValue("state") ==3) {
g_form.setVariablesReadOnly(true);
}
else
{
g_form.setVariablesReadOnly(false);
}

Mark this comment and my earlier comment(s) as HELPFUL if it helps.