Hideing variables in the Incident Variable Editor

Sam Ogden
Tera Guru

Hi All,

I have created a record producer to be used on a customer portal to create incidents.   This has many variables, but the answer to 'what is the incident related to?' (inc_rel_to) decides which variables appear to the user to be answered.

I have add the Incident Variable Editor to the incident form, but I only want this to show the variables that have been answered - currently it displays all the variables on the record producer regardless of if these were visible when the ticket was submitted.

I have created the display business rule on the incident table:

find_real_file.png

I have also created the following client script:

find_real_file.png

However all the variables are displaying when I load an incident in the normal servicenow UI that has been created by my record producer.

Any help as to where I am going wrong will be greatly appreciated.

Thanks

Sam

1 ACCEPTED SOLUTION

Sam, ok reworked the script.   I found if I hid the container start and end fields, the entire variable formatter disappeared so I commented those lines out and added specific code NOT to hide them.   I added code to hide the "mapped" fields as well.   Here is my entire business rule script:


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


      var hideTypes = [];


      hideTypes.push("11"); //Label


   


      g_scratchpad.emptyVars = "";


      var emptyVars = [];


   


      var producerVars = new GlideRecord("question_answer");


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


      producerVars.query();


      while (producerVars.next()) {


              // First check to see if container and if so continue since hiding will cause issues


              if (producerVars.question.type == "19" || producerVars.question.type == "20") {


                      continue;


              }


           


              // Second check to see if variable type is one we always want to hide


              if (hideTypes.indexOf(producerVars.question.type) > -1) {


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


                      continue;


              }


           


              // Third check if variable is mapped to field, if so skip it


              if (producerVars.question.map_to_field == true) {


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


                      continue;


              }


           


              // Fourth skip any variable with a Null value


              if (gs.nil(producerVars.value)) {


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


                      continue;


              }


           


              // Fifth check if variable is a checkbox and hide if default value of false


              if (producerVars.question.type == "7" && producerVars.value == "false") {


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


                      continue;


              }


      }


      g_scratchpad.emptyVars = emptyVars.join();


})(current, previous);


View solution in original post

23 REPLIES 23

Hi Ashutosh,



I need this to be dynamic, so if more variables get added in the future the script will still cater for these.  


From what I can see line 6 of my client script is doing what was suggested in the first link you provided?



Thanks



Sam


Nate23
Mega Guru

Sam,



It looks like you pulled this from the SNGuru Site. Have you tried displaying infomessages to see if your scratchpad variable is populated? Also, be sure your BR is set to run onDisplay.


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

In your Business Rule you never declare the emptyVars variable as an array.   Add the following at line 3 and this should solve your issue:


var emptyVars = [];