How to hide lookup select box that has no choices

Stephen W_
Giga Guru

I've got a lookup select box variable dependent on another lookup select box variable via a reference qualifier.  
Is there a direct way to say "hide if empty" when viewing in the catalog?  

Thanks!

3 REPLIES 3

Mike Allen
Mega Sage

Are you saying that if there is nothing to choose, then hide it.   Like, you expose field2 based on the value of field1, and if field2 has no choices, then hide the field?   Or do you just want to expose when field1 has not been filled in.



Option A, in my mind, calls for a client script that does an AJAX call to the table, tries to find the number of choices and hides on 0, like:



var ajax = new GlideAjax('myScriptInclude');


ajax.addParam('sysparm_name', 'findRowCount');


ajax.addParam('sysparm_value', g_form.getValue('myVariable');


ajax.getXML(returnRowCount);



function returnRowCount(response) {


    var answer = response.responseXML.documentElement.getAttribute("answer");


    if(answer == 0){


                  g_form.setVisible('variable', false);


    }


}



find_real_file.png



var myScriptInclude = Class.create();


myScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  findRowCount: function(){


  var record = new GlideRecord('table');


  record.addQuery('field', this.getParameter('sysparm_value'));


  record.query();


  return record.getRowCount();


  },


      type: 'myScriptInclude'


});



Or something like that.



If option B, then add a Catalog UI Polocy:



find_real_file.png


find_real_file.png


Was looking for your option A, though for some reason I was thinking I had seen something like a "hide when empty" checkbox.  
Client script with ajax is doable, but pure client-side would be more efficient since all the information is already there.



Seems like this should exist:
if (!g_form.getChoices('lookup_field").count) {
        g_form.setDisplay('lookup_field",false);


}


Yeah, my suggestion was for both things being reference fields.   You are absolutely correct, though; if it has it's own choice list, go with the simple client script.