Add Record Producer Variables in email notification

Brian S5
Kilo Sage

I created a Record Producer with a couple of questions. I created a email notification to trigger on submission and I would like to know how I can include the answers to the variable questions. I've tried a few scripts from posts in the forums where users had a similar issue, however I cant seem to get the logic correct to have the variables show as they aren't visible in the select variables section on the right hand side of the notification message. I tried the links below and a couple of others. So far all I get is a blank notification.

 

 

 

Showing Request Item / Catalog Variables in Mail Script

 

Add request item variables to approval email comments

9 REPLIES 9

Have you tried the mail script that is provided in the request.itil.approve.role email template? It has a simpler version of the code you are using and may possibly give you an easier point to start from.


Brian S5
Kilo Sage

Ok, so ive finally found some more time to play with this setup. Ive went ahead and used the request.itil.approve.role email template as well as copied the text and manually put it into the HTML code section and it still doesnt pull the variables and put them in the email notification. Here is the code and the notification.



"CODE:


Short Description: ${sysapproval.short_description}


Priority: ${sysapproval.priority}


Requested For: ${sysapproval.requested_for}


Requested By: ${sysapproval.opened_by}


Total Price: ${sysapproval.price}


<hr/>


<mail_script>


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


  var item = new GlideRecord("sc_req_item");


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


  item.query();


  while(item.next()) {


          var nicePrice = item.price.toString();


          if (nicePrice != '') {


                  nicePrice = parseFloat(nicePrice);


                  nicePrice = nicePrice.toFixed(2);


          }


          template.print(item.number + ":   " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at $" + nicePrice + " each \n");


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




          var keys = new Array();


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


              }


          }


  }


</mail_script>


Comments:


${sysapproval.description}


<hr/>


${mailto:mailto.approval}


<hr/>


${mailto:mailto.rejection}


<hr/>


Click here to view Approval Request: ${URI}


Click here to view ${sysapproval.sys_class_name}:   ${sysapproval.URI}"



Notification:



Short Description:


Priority:


Requested For:


Requested By:


Total Price:



 


Summary of Requested items:



Comments:




 


Click here to approve



 


Click here to reject



 


Click here to view Approval Request: LINK


Click here to view :



Ref:MSG0018677


Check this post:


https://community.servicenow.com/thread/145257


Brian S5
Kilo Sage

i tried implementing that code as well. Now im getting just a blank response in my email box. The subject that i entered shows up in the subject line of the email but the body comes out blank with just a REF: MSG at the bottom.


I tried the code from B-rad.



<mail_script>  


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


var gr = new GlideRecord("sc_req_item");  


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


gr.query();  


while(gr.next()) {  


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


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


var varown = new GlideRecord('sc_item_option_mtom');  


varown.addQuery("request_item", current.sysapproval);  


varown.orderBy("sc_item_option.order");  


varown.query();  


while (varown.next()){  


var visible = varown.sc_item_option.item_option_new.visible_summary;  


var question = Packages.com.glideapp.questionset.Question.getQuestion(varown.sc_item_option.item_option_new);  


question.setValue(varown.sc_item_option.value);  


if (question.getLabel() != "" &amp;&amp; question.getDisplayValue() != "" &amp;&amp; visible == true){  


template.space(4);  


template.print('         ' +   question.getLabel() + " = " + question.getDisplayValue() + "\n");  


}  


}


}  


</mail_script>  




Im running calgary Patch 2


I also had issues when I did some more complex email scripts.


What helped was to grab one of the scripts from the community and then implementing it piece by piece and not the full script in one shot.


That way you are sure that until when it works and where an error occurs.



Additionally you can also set some gs.log statements.