gel is not a function in Catalog Item OnChange in ITIL

Jertay
Tera Contributor

I'm using a list collector in a catalog item. I need to check if the left bucket is empty on change, if so, enable a second field. I wrote a script that tries to get the left bucket using "gel", but when I run it in the ITIL view, it throws a JavaScript error saying "gel is not a function" and doesn't work. I unchecked "Isolate script" as well. Here's my code:

function onChange(control, oldValue, newValue, isLoading){
  if(isLoading || newValue == ''){
    return;
  }
  var left_bucket = gel('item_select_0'); // This causes the error
  if(left_bucket.options.length==0){
    g_form.setReadOnly('completely_remove', false);
  }
  else{
    g_form.setReadOnly('completely_remove', true);
  }
}
4 REPLIES 4

I should have mentioned that originally "Isolate script" was checked and I tried to use "document.getElementById('item_select_0')" and I got a JavaScript error of "Cannot read property 'getElementById' of null", so I guess it's not recognizing my "document" reference, which is why I unchecked "Isolate script". Any other ideas? Was this fixed with a patch or something?

Pranav Bhagat
Kilo Sage

'gel' is simply a shortcut for 'document.getElementById', which is standard javascript.you can turn on isolate scripts and use document.getElementById

https://www.w3schools.com/jsref/met_document_getelementbyid.asp

 

Thanks 

Pranav

Pranav, why it's not writen in documentation? And all the solusions are make from onChange or some other tolls. 

Why we can't use just the javascript? Like document.getElementById.outerHtml?