glide_list operation from client Script

pbo
Mega Expert

I need to manipulate glideList variable from catalog client script and found 2 post on this

https://servicenowgems.com/2016/11/14/setting-value-on-catalog-glidelist/?blogsub=confirming#blog_su...

and

https://servicenowgems.com/2016/11/22/clearing-values-on-catalog-glidelist/

This works well when code is directly inserted into client script but we need to call these functions from different client scripts and would like to avoid code duplication.

I created a new UI script with 2 functions

var GlideListHandler = Class.create({

  glideListClearValue : function (variable) {

  var ref = g_form.resolveNameMap(variable);

  if (!ref) {

  return;

  }

  var sourceSelect = $('select_0' + id);

  var sourceOptions = sourceSelect.options;

  var sourceSelectLength = sourceSelect.length;

  for (var i = 0; i < sourceSelectLength; i++) {

  sourceSelect.remove(0);

  sourceSelect.disabled = true;

  sourceSelect.disabled = false;

  }

  toggleGlideListIcons(id);

  if ($(ref + "_unlock").visible()) {

  $(ref + '_unlock').click();

  $(ref + '_lock').click();

  }

  },

  glideListSetValue : function (variable,listIds,listNames) {

  var liDs=[];

  var lNames=[];

  liDs=listIds.split(',');

  lNames=listNames.split(',');

  var ref = g_form.resolveNameMap(variable);

  if (!ref) {

  return;

  }

  $(ref + '_unlock').click();

  for (var i=0;i<liDs.length;i++) {

  addGlideListChoice('select_0' + ref,   liDs[i], lNames[i]);

  }

  $(ref + '_lock').click();

  },

  type: "GlideListHandler"

});

And in catalog client script (on change), I tried this code to clear a glide_list variable called List

if (newValue == 'true'){

  var glHandler = new GlideListHandler(g_form);

  glHandler.glideListClearValue('List');

  }

But this doesn't work as expected : List variable still shows selected values when locked (values disappear when List is unclocked)

Any idea ?

1 ACCEPTED SOLUTION

pbo
Mega Expert

I found errors in my code



  var sourceSelect = $('select_0' + id);


...


  toggleGlideListIcons(id);



should be


  var sourceSelect = $('select_0' + ref);


..


  toggleGlideListIcons(ref);



And this works using UI Script


View solution in original post

4 REPLIES 4

bernyalvarado
Mega Sage

Hi Patrick, have you marked your UI script as global?



Thanks,


Berny


bernyalvarado
Mega Sage

You may also want to create another catalog client script which contains an empty definition of a catalog client script and below it the definition if your "class" with the two functions.



You may also want to try out just to declare the functions without using the class prototype approach.



Thanks,


Berny


I hope this helps!



Thanks,


Berny


pbo
Mega Expert

I found errors in my code



  var sourceSelect = $('select_0' + id);


...


  toggleGlideListIcons(id);



should be


  var sourceSelect = $('select_0' + ref);


..


  toggleGlideListIcons(ref);



And this works using UI Script