Clearing Values On Catalog GlideList

A few days ago I posted custom functionality on how to set the value of GlideList variables. Today I had a request from a colleague to find out how to create an equivalent function to g_form.clearValue(variableName) on a GlideList. Again, it turns out this hasn’t been implemented for the new variable GlideList (amongst other functionality). I assume these will all be added over time in the future release, but for now, I wrote a quick function that can be used to replicate the functionality:

function glideListClearValue(variable) {
 var id = g_form.resolveNameMap(variable);
 if (!id) {
  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 ($(id + "_unlock").visible()) {
  $(id + '_unlock').click();
  $(id + '_lock').click();
 }
}Now when you want to clear the value, just run the function glideListClearValue(variableName) and the function will take care of the rest.

Two things to remember here. One, because of the accessing the DOM directly, this will NOT work on the new service portal. Sorry not much I can do about that.

Secondly, when you upgrade, check if there’s an OOB function which makes this code redundant. It’s always better to stick to the standard functions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s