Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trying to hide empty variables

Stanley1993
Tera Contributor

Hi Guys! I am trying to hide the empty variables on my form but it seems like it is working for the variables that are not under/in my Catalog UI Policies. Every variabel that i have under the Catalog UI Policies is not affected. It i can see that they are empty but it is still not working.
I am using the following BR (Picture 1):

var emptyVariables = [];
var tableName = current.getTableName();
var ritmSysId = '';
if (tableName == 'sc_req_item')
    ritmSysId = current.getUniqueValue();
if (tableName == 'sc_task')
    ritmSysId = current.request_item;
var itemObj = new GlideRecord('sc_item_option_mtom');
itemObj.addQuery('request_item', ritmSysId);
itemObj.addNullQuery('sc_item_option.value');
itemObj.addQuery('sc_item_option.item_option_new.type', '!=', 11); // exclude label
itemObj.addQuery('sc_item_option.item_option_new.type', '!=', 19); // exclude container start
itemObj.addQuery('sc_item_option.item_option_new.type', '!=', 20); // exclude container end
itemObj.query();
while (itemObj.next()) {
    var name = itemObj.sc_item_option.item_option_new.name;
    emptyVariables.push(name.toString());
}
g_scratchpad.emptyVariables = emptyVariables.toString();


I also have Catalog Client script (Picture 2):

function onLoad() {

    if (g_scratchpad.emptyVariables != '') {
        var emptyVars = g_scratchpad.emptyVariables.split(',');
        for (i = 0; i < emptyVars.length; i++) {
            g_form.setDisplay(emptyVars[i], false);
        }
    }
}
Picture 1.pngPicture 2.png

  

1 REPLY 1

Anurag Tripathi
Mega Patron
Mega Patron

Hi ,

See this, this page has the script and also explains the logic behind it

Toggle Show/Hide Empty Variables | by ServiceNow Scholar | Medium

 

OR

Hide Empty Variables on a Standard Form - ServiceNow Guru

-Anurag