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

Justin Abbott
Giga Guru

I have this functionality set up on a custom table in my instance. Maybe you can compare yours to mine and see what's different.



Here's how my display business rule is set up:



Condition:


!RP.isPopup()



Script:


(function executeRule(current, previous /*null when async*/) {




//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 = [];


var table = current.getTableName();


//Query for the empty variables for this record


//Catalog item and task variables pull from 'sc_item_option_mtom' table


if(table == 'sc_req_item' || table == 'sc_task'){


var itemVars = new GlideRecord('sc_item_option_mtom');


if(table == 'sc_req_item'){


itemVars.addQuery('request_item', current.sys_id);


}


if(table == 'sc_task'){


itemVars.addQuery('request_item', current.request_item.sys_id);


}


itemVars.addNullQuery('sc_item_option.value');


//Exclude Label and Container variables


itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 11);


itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 19);


itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 20);


itemVars.query();


while(itemVars.next()){


//Add variable names to the emptyVars array


emptyVars.push(itemVars.sc_item_option.item_option_new.name.toString());


}


}


else{


//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();


}




})(current, previous);


That's the one that I modified but I pulled that top piece out after that didn't work either. I kept the bottom piece cause this is a Record Producer instead of a request.


The script editor doesn't seem to like if((!(RP==null))&&!RP.isPopup()), but I'm not sure if that has anything to do with the script not working.



Maybe try adding logging along the way to see which points the script is getting to.


I compared it to yours and made a couple adjustments. I don't need the Request part which i tried it with it in and it didn't work either. I must still be missing something - I also have a Client Script pulling that BR onLoad but not much going on with that.



function executeRule(current, previous /*null when async*/){  



//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 = [];


      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_11-24-34.png