User Criteria not working

ewilks
Giga Expert

I set up a User Criteria that includes users of a particular role.  

Then I went into a catalog item and in the Available For I added the User Criteria that I created above.   Now, everyone can see it.   ServiceNow, for the love of all that is holy, what is the point of doing nonsense this when it doesn't work?

So now I'm left with adding a Not Available For where I will make it unavailable for:

1. Users with ITIL roles (easy to set up)

2. Users without roles - I create a new user criteria and check advanced.   In the code box, I've tried number of different versions of this, but I get this error ("JavaScript parse error at line (2) column (6) problem = invalid return"), so can I get some help?

if(!gs.getUser().hasRoles()){

return true;

} else{

return false;

}

Please, ServiceNow, in the name of all that is holy, explain to me why you would bother replacing something that did work with something that doesn't.   How does that serve anyone, especially ServiceNow?

When I envision the developers at ServiceNow, I see a bunch of people wearing only black, studded leather carrying whips.   It must be the dress code there, correct?

1 ACCEPTED SOLUTION

ewilks
Giga Expert

Created a new user criteria called, "User with no roles"


checked advanced


added the following to the script:


if(!user.HasRoles()) {


condition =false;


}



Added that user criteria to the catalog item's not available for:



Long story short, indicating which user criteria to use to share a catalog item with isn't enough.


View solution in original post

13 REPLIES 13

I ll mimic the scenario tomorrow in my Dev instance to check if it is the same problem for me as well. I have also marked Shashank already in the thread if he can put some insights to that as well.


Thanks Deepak.  


Here's an update.   I removed the User Criteria from the available for saved it and went back in and added the exact same user criteria again.   It's working a little bit better.


Now, it only allows those users with the role in the User Criteria to access and rejects those users with a role that's not in the user criteria.   But it still allows users that have no role to access it.  



So here's how it works:


Asked ServiceNow to give candy only to users in princess costumes.


ServiceNow now only gives candy to users dressed as princesses AND anyone who doesn't have a costume.



ServiceNow is a spectacularly expensive puppy that won't stop chewing on my $#1&% slippers.


HI Deepak,



I have a user criteria scenario which is not working. can u have a look at my code and comment?



accessviagroup();



function accessviagroup(){


  var x = false;


  var loggedin = gs.getUserID();


  var m_member = new GlideRecord('sys_user_grmember');


  m_member.addQuery('user',loggedin);


  m_member.addQuery('group.name','STARTSWITH', "Int");


    if(m_member.next()){


 


  x = true;



  }



  return x;



}


Have you tried replacing this line with the one following?  


// if(m_member.next()){


while(m_member.next()){


  x = true;



  }



  return x;



}