Include catalog item's properties in Request table notification email

SC10
Kilo Guru

I've created a new 'translated html' field on the Catalog Item form, similar to that of "Description", to add in some more information to my catalog items.

I'd like to use this additional information in the emails that send out when the catalog item's Request (sc_request table) is closed.

Can I dot walk to the properties of my Catalog Item? Can I pull the display value of my new 'translated html' field even? I tried doing a mail script to pull the data of my new "testinfo" field, but it comes back as undefined:

<mail_script>

    var gr = new GlideRecord("sc_req_item");

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

    gr.query();

    while(gr.next()) {

    template.print(gr.testinfo.getDisplayValue());

  }

</mail_script>

1 ACCEPTED SOLUTION

Good day,



I was able to get this working after using the following code:



var gr = new GlideRecord("sc_req_item");


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


    gr.query();


    while(gr.next()) {


    template.print(gr.cat_item.u_test_info.getDisplayValue());


  }



This works as the email notification is running off of the Request table.



Thank you for everyone's time, especially Venkat who assisted me along with this day after day.


View solution in original post

32 REPLIES 32

venkatiyer1
Giga Guru

Hi Shane,



Then that didnt work obviously. Thanks for letting me know as well. Please remove the table name from the query.


If you are in Eureka release or later, please try mail script. I guess that would resolve the issue. Link is below.



Scripting for Email Notifications - ServiceNow Wiki


Good day,



I have been using a mailscript. Have I misunderstood what you're suggesting?



Thanks.


venkatiyer1
Giga Guru

Hi Shane,



If you go to section 2 of the link below, you will see an option to create an email script seperately and then refer it in template as   ${mail_script:script name}



Scripting for Email Notifications - ServiceNow Wiki



I felt that way you will be get your values from requested item and populate it.


Not much luck there. This is the mailscript that I have created:



(function runMailScript(current, template, email, email_action, event) {


  var gr = new GlideRecord("sc_req_item");  


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


    gr.query();  


  while(gr.next()) {


template.print(gr.u_test_info);


}  


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





I have tested this with template.print(gr.u_test_info); and template.print(gr.u_test_info.getDisplayValue());, and neither are working.



Any ideas?


venkatiyer1
Giga Guru

Hi Shane,



Which version of ServiceNow are you in? The reason i am asking in Geneva, I just get a plain version when i try to access Notification Scripts.



We need to create a notification email script say requested_item_test_info and inside it




var gr = new GlideRecord("sc_req_item");  


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


    gr.query();  


  while(gr.next()) {


template.print(gr.u_test_info); //or   template.print(gr.u_test_info.getDisplayValue())


}  




Then inside your template where you had this code initially, replace the above code with   ${mail_script: requested_item_test_info}


You can find notification email scripts under Email in the filter navigator.