Advanced Script for User Criteria

tim_harris
Giga Expert

I am trying to use an advanced script for User Criteria. On the wiki the only documentation says that the script field is "A script to define any additional criteria, and return true or false. This field is available only if Advanced is selected."

There is no example provided. I can't figure out how to reference the user record. For example, if I want to say all users who are active. How would I do this? I know the basic logic, but am unsure of how to reference the user record in the script.

Example logic:

if (currentUserRecord.active == true) {

      return true;

} else {

      return false;

}

Any help would be appreciated.

Thanks,

Tim

1 ACCEPTED SOLUTION

ahaz86
Mega Guru

take a look at this page http://www.servicenowguru.com/scripting/user-object-cheat-sheet/



gs.getUser().getRecord().getValue('active') == true


View solution in original post

11 REPLIES 11

randrews
Tera Guru

for those that can't make this a simple query like that.... in geneva you have to wrap the answer in a function like this.



answer();



function answer(){


      var job = gs.getUser().getRecord().getValue('u_job_family');


      if (job == "Human Resources"){return true;}


      else{return false;}


Nestor2
Giga Contributor

Thank you for that, I had to go that road, since dot walking was not working for me:

 

I did this:

//Getting the data of the current user
var grUser = new GlideRecord("sys_user");
grUser.addQuery("sys_id", gs.getUserID());
grUser.query();

//getting the value of L1R
if(grUser.next()){
answer = grUser.getValue('u_l1r') == true;
}

 

 

Regards,

 

N.