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

Yes tried info message same Message showing null

 

I think because of im an admin??

 

This line should return true to you as you are admin.

g_user.hasRole('admin')

I see there are few issues in your script include and client scripts. I have updated them here.

1. Your script include is not checked as client callable. 

2. you are passing group_id to script include but isMemberof accepts group name.

I have modified your code slightly. Try this once and tell me what is the output.

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_groupName',g_form.getValue('assignment_group'));
 ga.getXML(hideField);
 
 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);
   }
  }
 }

}

 

Script Include

 

var MyGroups = Class.create();
MyGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 initialize:function() {
 },
 isGrpMember:function() {
   var userID = this.getParameter('sysparm_userID');
   var groupID = this.getParameter('sysparm_groupName');
   //get the group name based on the group id
   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';
});

 

check system logs as well to check if you are getting the gs log statements and sharre me the otuput if it does not work. 

Mark the comment as a correct answer and also helpful once worked.

Its not working asif, Still anon admin user able to edit the varaibles

Hello Nag,

First tell me what is the output you have seen based on the script that i shared? Did you update both the scripts that i shared?

Did you make the script include "client callable" checked?

In the logs is it returning the correct value?

What is the output of the client scirpt?

 

Below is the output of client script

 

find_real_file.png

script include "client callable" checked?, Done this one also