Help with a Business Rule to Not Display Empty Variables from a Record Producer on a Certain Table

Wendy Peterson
Giga Guru

Hi, I have a table called AOM Bandwidth (u_aom_bandwidth) and i need to hide variables that are empty. I copied a script from our request table but it's not working. Any ideas? See the table has the variables on it and its looking for the sys id of that table not sure what is wrong? I even tried to update the Table line to look for that specific sys id... that didn't work either

producerVars.addQuery('table_sys_id', '786da04313034f00561059812244b063');//removed current.sys_id

The Business Rule is on Display

if((!(RP==null))&&!RP.isPopup()){

   

//Initialize the scratchpad variable

g_scratchpad.emptyVars = '';

//Check to see if a variable pool exists

var count = 0;

for(vars in current.variable_pool){

      count++;

      break;

}

//If a variable pool exists then collect empty variable names

if(count > 0){

      var emptyVars = new Array();

      var table = current.getTableName();

      //Query for the empty variables for this record

      if(table == 'u_aom_bandwidth'){

            //All other variables pulled from 'question_answer' table

            var producerVars = new GlideRecord('question_answer');

            producerVars.addQuery('table_sys_id', current.sys_id);

            producerVars.addNullQuery('value');

            //Exclude Label and Container variables

            producerVars.addQuery('question.type', '!=', 11);

            producerVars.addQuery('question.type', '!=', 19);

            producerVars.addQuery('question.type', '!=', 20);

            producerVars.query();

            while(producerVars.next()){

                  //Add variable names to the emptyVars array

                  emptyVars.push(producerVars.question.name.toString());

            }

      }

    //Store the result in the scratchpad

      g_scratchpad.emptyVars = emptyVars.join();

}

}

2017-12-19_9-53-01.png

6 REPLIES 6

eval can be harmful.



Here's my client script, for comparison:


function onLoad() {


//Hide all empty variables using the scratchpad object passed from 'Hide Empty Variables' business rule


if(g_scratchpad.emptyVars != ''){


var emptyVars = g_scratchpad.emptyVars.split(',');


for(i = 0; i < emptyVars.length; i++){


g_form.setDisplay('variables.' + emptyVars[i], false);


}


}


}



I wish I could help troubleshoot more in depth!


I think it might be something with the onLoad client script cause when I run debug it keeps telling me that emptyVars is undefined. shrug