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 Nag,

I just made few changes. Here is the updated script include. Try this and let me know the output.

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'
});

 

Modified the script include

Below is the output im getting in client script

 

 

So you got answer as false, which means the user is not a member of the group.

But the 2nd one returned true, which mean sthe user whom you are checking this is admin. so it returned true.

!true = false, hence it is not entering your if condition in the client script. 

 

check with any other non-admin user once.

 

Hi Nag,

Did you check as non-admin user?

If yes, kindly mark my comment as a correct answer and all my other comments as helpful if this has helped you in solving it.

yes checking give 10  mins time