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) {
 var sourceSelect = $('select_0' + id);
 var sourceOptions = sourceSelect.options;
 var sourceSelectLength = sourceSelect.length;
 for (var i = 0; i < sourceSelectLength; i++) {
  sourceSelect.disabled = true;
  sourceSelect.disabled = false;
 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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.