Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

User Criteria Scripting Issue

guzman
Giga Guru

Hi All,

 

Maybe someone out there help me to debug this small script in User Criteria.

I created a User Criteria script to determine if a user is a member of any group whose name starts with the prefix ‘IT Support’, and although it works fine in Scripts-background by returning true is the logged in user is a member of a group starting with 'IT Support...', , it fails to do so when implemented in the User Criteria.

I am not sure if there is a better way to implement it, or if I am missing something, When I impersonate a member of one of any 'IT Support...' group, it fails to show the catalog item for them. 

 

Name: Group Names Starting with IT Support

---------------------------------------------------------

 

IsAnITSupportMember();

 

//To grant access to this catalog item to members of any group whose name starts with 'IT Support'.
function IsAnITSupportMember() {
      var loggedInUser = gs.getUserID();
      var user_Rec = new GlideRecord('sys_user_grmember');
      user_Rec.addQuery("sys_id", loggedInUser);                                       // it also fails when using "user.sys_id"
      user_Rec.addQuery("group.name", "STARTSWITH", "IT Support");  // It also fails when using "group"
      user_Rec.setLimit(1);
      user_Rec.query();

     if (user_Rec.next())
          return true;
     else
         return false;
    }

}

 

---------------------------------------------------------

 

Thanks,

Juan

1 ACCEPTED SOLUTION

You can try something like this

var member = new GlideRecord('sys_user_grmember');
member.addQuery('user', user_id);
member.addEncodedQuery('group.nameLIKEIT Support');
member.setLimit(1);
member.query();
answer = member.hasNext();

 

Note: sometimes with new user criterias you might need to logout/login and clear the cache before testing.

 

 

 

View solution in original post

3 REPLIES 3

Mike_R
Kilo Patron

Best way is to just add all of the groups to the Groups field

Mike_R_0-1674830371324.png

 

 

Thank Mike for your prompt reply.

 

I had it that way, but I was then asked to do dynamically, so that when a new 'IT Support...' group is created, we do not have to enter the group manually.

 

Thanks,

Juan

You can try something like this

var member = new GlideRecord('sys_user_grmember');
member.addQuery('user', user_id);
member.addEncodedQuery('group.nameLIKEIT Support');
member.setLimit(1);
member.query();
answer = member.hasNext();

 

Note: sometimes with new user criterias you might need to logout/login and clear the cache before testing.