Notification displaying sys_id instead of value for reference variables

drew_plastridge
Kilo Contributor

I am trying to include all our requested item variables in our email notifications.   It's working great except when the variable is a reference like "Requested For" or "Application."   instead fo the value I get the sys_id from the table its referencing.   I see it may be possible to use getDisplayValue().   However, we use multiple reference fields.   Is there a way to do this without specifing which table to get the value from?

Here is my current code:

var item = GlideRecord("sc_req_item");

item.addQuery('sys_id','71bb57fb0f93030059daba8ce1050e11');

item.query();

while(item.next()){

        var c_item = GlideRecord("sc_cat_item");

        c_item.addQuery('sys_id',item.cat_item);

        c_item.query();

        while(c_item.next()){

                  gs.info("<a href='" + "sp?id=ticket&table=sc_req_item&sys_id=" + item.sys_id + "'>" + item.number + "</a>:   " + c_item.name + " <br />");

                  var item_vbls = new GlideRecord("sc_item_option_mtom");

                  item_vbls.addQuery('request_item', item.sys_id);

  item_vbls.orderBy('sc_item_option.order');

                  item_vbls.query();

                  while(item_vbls.next()) {

                  gs.info("<b>" + item_vbls.sc_item_option.item_option_new.question_text + ": </b>" + item_vbls.sc_item_option.value + "<br />");

}  

}

}

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

Here is a Notification Email Script that I use to generate variables for a Requested Item:



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {


     


      //template.print("Summary of Requested items:\n");


      var item = new GlideRecord("sc_req_item");


      item.addQuery("request", current.sys_id.toString());


      item.addQuery("request", "!=", "");


      item.query();


      while(item.next()) {


              template.print(item.number + ":   " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at " + item.price.getDisplayValue() + " each \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");


                      }


              }


      }


     


})(current, template, email, email_action, event);


View solution in original post

2 REPLIES 2

ccajohnson
Kilo Sage

Here is a Notification Email Script that I use to generate variables for a Requested Item:



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {


     


      //template.print("Summary of Requested items:\n");


      var item = new GlideRecord("sc_req_item");


      item.addQuery("request", current.sys_id.toString());


      item.addQuery("request", "!=", "");


      item.query();


      while(item.next()) {


              template.print(item.number + ":   " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at " + item.price.getDisplayValue() + " each \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");


                      }


              }


      }


     


})(current, template, email, email_action, event);


Thanks Christopher, that works perfectly!