Catalog Client Scripts not working for non-admin roles

John Reynolds
Mega Expert

Hello,

I am on Helsinki Patch 6.

I have a record producer that submits a record to the incident table.   I have 3 fields on the record producer, Category, Subcategory, and Subcategory Type, that are all dependent on each other.   Subcategory Type should only populate for certain subcategories   I have created several catalog client scripts to control this functionality.   These client scripts work without issue when testing them on my Admin account, however when I switch over to an ITIL or ESS user, the scripts do not function correctly.

Example:

Admin User Non-Admin User (ESS)

I have the following Catalog Client Scripts active:

- Clear Subcategory onLoad

function onLoad (control, oldValue, newValue, isLoading) {

      g_form.clearOptions('subcategory');

}

-Category / Subcategory Dependency (onChange)

function onChange(control, oldValue, newValue, isLoading) {

if(newValue == oldValue){

return;

}

//remove all items from subcategory drop down to start

g_form.clearOptions('subcategory');

//build a new list of dependent options

var gp = new GlideRecord('sys_choice');

gp.addQuery('dependent_value', newValue);

gp.addQuery('element', 'subcategory');

gp.addQuery('inactive', 'false');

gp.orderBy('label'); //Order subcategory by the label value

gp.query();

while(gp.next()){

  g_form.addOption('subcategory', gp.value, gp.label);

}

}

-Clear Subcategory Type onLoad

function onLoad (control, oldValue, newValue, isLoading) {

g_form.clearOptions('u_subcategory_type');

}

- Subcategory / Subcategory Type Dependancy

function onChange(control, oldValue, newValue, isLoading) {

if(newValue == oldValue){

return;

}

//remove all items from subcategory drop down to start

//g_form.clearOptions('u_subcategory_type');

//build a new list of dependent options

var gp = new GlideRecord('sys_choice');

gp.addQuery('dependent_value', newValue);

gp.addQuery('element', 'u_subcategory_type');

gp.orderBy('label'); //Order subcategory by the label value

gp.query();

while(gp.next()){

  g_form.addOption('u_subcategory_type', gp.value, gp.label);

}

}

Everything works 100% correct and as intended on admin role accounts but nothing else and I've been having the toughest time trying to figure out why.   Has anyone seen anything like this or can shed some light on where to look to try and resolve it?

1 ACCEPTED SOLUTION

Ben LaChance
Kilo Expert

Usually when I run into problems like this, it's related to the ACLs on the tables that you're linking to.   I would check and make sure that the non-admin user has read access on the fields that are being accessed by the client script.   Hopefully granting read access will clear up the issue.



EDIT:   I've also found that some judicious use of gr.getRowCount() can be very useful in cases like this to make sure that you're actually getting the number of records (or any records at all) from your GlideRecord queries, without having to try to delve into actual GlideRecord objects that might or might not exist.


View solution in original post

12 REPLIES 12

Did you try using CallBack function as i mentioned earlier?


Thanks Abhinay.



I did and it was still unsuccessful.


johnreynolds



I know where the problem is, you are not checking for isLoading in onChange client script. Use these onChange client scripts



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading) {


  return;


  }



  if(newValue == oldValue){


  return;


  }


  //remove all items from subcategory drop down to start


  g_form.clearOptions('subcategory');



  //build a new list of dependent options


  var gp = new GlideRecord('sys_choice');


  gp.addQuery('dependent_value', newValue);


  gp.addQuery('element', 'subcategory');


  gp.addQuery('inactive', 'false');


  gp.orderBy('label'); //Order subcategory by the label value


  gp.query(CallBack);


  function CallBack(gp){


  while(gp.next()){


  g_form.addOption('subcategory', gp.value, gp.label);


  }


  }



}





function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading) {


  return;


  }



  if(newValue == oldValue){


  return;


  }


  //remove all items from subcategory drop down to start


  //g_form.clearOptions('u_subcategory_type');



  //build a new list of dependent options


  var gp = new GlideRecord('sys_choice');


  gp.addQuery('dependent_value', newValue);


  gp.addQuery('element', 'u_subcategory_type');


  gp.orderBy('label'); //Order subcategory by the label value


  gp.query(CallBack);


  function CallBack(gp){


  while(gp.next()){


  g_form.addOption('u_subcategory_type', gp.value, gp.label);


  }


  }


}