Variables in Mail Scripts

jalexander1
Kilo Contributor

I have read through all of the wiki blogs around this, but I'm still having two issues with the mails scripts.

1) The first issue is that I'd like to hide the unanswered variables and only display the answered variables. How do I correct the if line in order to accomplish this? Here is my script:

  var item = new GlideRecord("sc_req_item");

  item.addQuery("sys_id", current.sysapproval);

  item.query();

  while(item.next()) {

        template.print("Options:\n");

                var keys = [];

          var set = new GlideappVariablePoolQuestionSet();

          set.setRequestID(item.sys_id);

          set.load();

          var vs = set.getFlatQuestions();

          for (var i=0; i < vs.size(); i++) {

if(vs.get(i).getLabel() != '') { //This displays all of the variables (answered/unanswered)

    //   if(vs.get(i).getLabel() != '' && vs.getDisplayValue() != '' && visible == true); { //I've tried this line but it hides all of my variables

                    template.space(4);

                    template.print('         ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");  

              }

                }

  }

2) My second mail script issue is that I've created a custom table and I'm having a hard time with displaying the variables within my mail script/notifications. I'm pretty sure it is the addQuery line that is causing the issue, but what should this line be?   here is that script:

  var item = new GlideRecord("x_tebc2_fac_manage_fac_management_table"); //custom table

  item.addQuery("sys_id", current.sys_id); //I have tried different addQuery but nothing seems to work

      item.query();

  while(item.next()) {

      //   template.print(item.number + ":   " + item.quantity + " X " + item.cat_item.getDisplayValue() + "\n");

          template.print("Options:\n");

          var keys = [];

          var set = new GlideappVariablePoolQuestionSet();

          set.setRequestID(item.sys_id);

          set.load();

          var vs = set.getFlatQuestions();

          for (var i=0; i < vs.size(); i++) {

              if(vs.get(i).getLabel() != '') {

                    template.space(4);

                    template.print('         ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");  

              }

          }

  }

6 REPLIES 6

Yea, you may need to query the variables directly. I'd check to see if the test records have entries in sc_item_option_mtom which point to saved values in sc_item_option.


rajeevlochan82
Mega Guru

// If you think its addquery, can you please pass some hard-coded value in add-query and see the result....



var item = new GlideRecord("x_tebc2_fac_manage_fac_management_table"); //custom table


  item.addQuery("sys_id", current.sys_id); //I have tried different addQuery but nothing seems to work


      item.query();


  while(item.next()) {


      //   template.print(item.number + ":   " + item.quantity + " X " + item.cat_item.getDisplayValue() + "\n");


          template.print("Options:\n");


          var keys = [];


          var set = new GlideappVariablePoolQuestionSet();


          set.setRequestID(item.sys_id);


          set.load();


          var vs = set.getFlatQuestions();


          for (var i=0; i < vs.size(); i++) {


              if(vs.get(i).getLabel() != '') {


                    template.space(4);


                    template.print('         ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");


              }


          }


  }