Get Display Value and in mail script

jimpaige
Giga Contributor

Hi all,

I'm using this mail script to capture variables for a catalog item to be sent in a notification:

printVars();

function printVars() {

      template.print('<b>Catering Request Details</b>\n');

      var cv = new GlideRecord('sc_item_option_mtom');

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

      cv.addNotNullQuery('sc_item_option.value');

      cv.orderBy('sc_item_option.order');

      cv.addQuery('sc_item_option.value', '!=', '0');

      cv.addQuery('sc_item_option.value', '!=',"false");

      cv.query();

      while(cv.next()) {

          template.print('\n' + cv.sc_item_option.item_option_new.question_text + ':\t<b>' + cv.sc_item_option.value + '</b>');

      }

}

I have a few variables that are type Reference and for these the sys_id is returned.   I think need to include a getDisaplayValue condition in the script but not sure where to put, of if that is even the correct approach.   Any ideas anyone?

Thanks,

Jimmy

1 ACCEPTED SOLUTION

Here you go



template.print('<b>Catering Request Details</b>'+ "<br/>");


var set = new GlideappVariablePoolQuestionSet();


set.setRequestID(current.sys_id.toString());


set.load();


var vs = set.getFlatQuestions();


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


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


              template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br/>");


      }


}


View solution in original post

8 REPLIES 8

Abhinay,



You are a legend my friend!


Hi Jim,



I just saw your response.


Sorry for being late on this one.


No worries, Pradeep.   Thanks for your help.


aji1234
Kilo Explorer

You can write a mail script :




var dm = current.sys_domain;  


var val = current.state;  


var myLabel = Choice(dm,"state",val);  


template.print("<strong>State:</strong> "+myLabel);  


function Choice(a,b,c){  


    var query = 'sys_domain='+a+'^element='+b+'^value='+c;  


    var gr = new GlideRecord("sys_choice");  


    gr.addEncodedQuery(query);  


    gr.query();  


    if (gr.next()) return gr.label;  


}