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

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


HI Michael,



Thanks for your help on this, seems to have done the trick.


Apologies for all the questions on this - should be the last one:



I need to make the variables that now appear be read only.



I've tried adding line 7 on the client script, but this seems to send it in an endless loop when trying to load the incident form.



find_real_file.png



Thanks



Sam


Reverse the order.   The code cannot mark a field read only that isn't on the form.   Since you are hiding it first and then marking it read only its causing issues.


Cheers Michael realised my mistake.



Just confussed on the issue I'm getting with some of the checkbox fields.   I've checked and the 3 checkboxes are getting the value of true in the question_answers table.



Thanks


Hi Michael,



just noticed one other thing on this.   I have several variables where I have a label, and then multiple checkboxes. If I answer say 2 out of the 4 checkboxes, none of them are displaying in the variable editor.



Thanks