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

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


}
}