Requested Item Details in Email

Community Alums
Not applicable

At the Requested Item level we send an email to the approver and it contains the following mail script and it shows the requested item and all the variables associated with it which works great. However, we also want to send this detail in an email to the requested by user when the requested item has been completed. If we use the same mail script in that email it shows mulitple requested items and their variables instead of the one requested item.

I've tried different queries on the glide record as shown below but none of them work properly or wok at all.   Can someone please help me with get the correct glide record to show the requested item details to send out to the requested by in an email?

//Queries tried

//item.addQuery("request", current.sysapproval);

//item.addQuery("sys_id", current.document_id);

//item.addQuery("sys_id",current.request_item.sys_id);

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------

//template.print("Summary of Requested items:<br />");  

  var item = new GlideRecord("sc_req_item");

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

  item.query();

  while(item.next()) {

          var nicePrice = item.price.toString();

          if (nicePrice != '') {

                  nicePrice = parseFloat(nicePrice);

                  nicePrice = nicePrice.toFixed(2);

          }

          template.print(item.quantity + " x " + item.cat_item.getDisplayValue() + " <br />");

    template.print("       Details:<br />");

          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() != '' && (vs.get(i).getDisplayValue() != "-- None --") && (vs.get(i).getDisplayValue() != "") && (vs.get(i).getDisplayValue() !="false")) {

                    template.space(4);

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

              }

          }

  }

4 REPLIES 4

sowmyarajaram
Tera Expert

Aryanos,



Even I'm trying the same that to provide the detailed information when the request is submitted, but getting list of records instead of one. were you able to solve this?



Thanks,


Sowmya


Community Alums
Not applicable

Hi Sowmya,



I did get it to work by creating a Notification Email Script and with the code below and then in the email notification reference it. For example if I named the notification email script 'requested_item_detail' then in the notification you would reference it with ${mail_script:requested_item_detail}.



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


  var item = new GlideRecord("sc_req_item");


 


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


  item.query();


  while(item.next()) {


          var nicePrice = item.price.toString();


          if (nicePrice != '') {


                  nicePrice = parseFloat(nicePrice);


                  nicePrice = nicePrice.toFixed(2);


          }


         


          template.print(item.quantity + " x " + item.cat_item.getDisplayValue() + " <br />");


    template.print("       Details:<br />");




          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() != '' && (vs.get(i).getDisplayValue() != "-- None --") && (vs.get(i).getDisplayValue() != "") && (vs.get(i).getDisplayValue() !="false")) {


                    template.space(4);


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


              }


          }


  }


Thanks Aryanos!!



Hope this helps too...



var keys = [];


template.print("Summary of Requested Item:<BR>");


for (var key in current.variables) {


  var v = current.variables[key];


  if(v.getGlideObject().getQuestion().getLabel() != '') {


  template.print(v.getGlideObject().getQuestion().getLabel()   + " = " + v.getDisplayValue() + "<BR>");


  }


}



Thanks,


Sowmya


valeriemorris
Mega Expert

How can I modify this to only show the price if one exists? For example, I have an item called "Oracle Access Request," which shows the requestor "1 X Oracle Access Request at $0.00 each" and I would like to remove the "at $0.00 each" part since it's not relevant to that type of request.