The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Script help to restrict access to Catalog Item based on user field

nicolemccray
Tera Expert

On form load, I need a script that will prevent access and produce a pop up based on the employee number.   If the employee number has a 'negative' in front, they should not be able to access the form, and a pop up message should appear with some explanatory text.

1 ACCEPTED SOLUTION

I was able to achieve this with the following client script:




function onLoad() {
var rec = new GlideRecord('sys_user');
rec.addQuery('sys_id', "=", g_user.userID);
rec.query(recResponse);

function recResponse(rec) {
rec.next();
if(parseInt(rec.employee_number) < 0){
  alert("To order this service a contractor/non employee will require a sponsor to Order On Behalf to obtain database access.");
  history.go(-1);
  g_form.setDisplay('addSubmitButton',false);
}


}
}


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi Nicole,



Have you thought about using User Criteria to avoid displaying the catalog item altogether? You can write a script to find out if the employee ID starts with a "-" and deny the user access to that item.



Apply user criteria to items


I've created a script in my user criteria item:



find_real_file.png



But cannot figure out out to apply this to my Catalog Item.   I've looked in the 'Not Available For' and 'Not Available For User' options, but it is not there.   Where can I find my User Criteria item to add?


Hi Nicole,



You can add the related list(Not available for AND available for) on the maintain item record.



find_real_file.png





Right click on the maitain item record and go to related list and add the required option and save it.



Regards,


Atul Kumar


My take on the script, FWIW.



var user = new GlideRecord('sys_user');


user.get(gs.getUserID());


var empNum = user.getValue('employee_number');


return (empNum.indexOf('-') == 0);