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

Just wanted to clarify something.



The email notification is firing off of the sc_request table. I want to pull some field information from my sc_cat_item catogory item is that creating this req/ritm/task from my workflow.



The workflow ends, the ritm closes, the REQ closes from a business rule, and then my email notification fires off.



Does your example script hold true?


Yes it should. When we are 'getting' current, we are using the get() method to grab the current record. In your case it is a particular Request (REQ) record. This record should have at least one Requested Item (RITM). Your original script used gr as the object name, but I changed it to itmObj for better clarity as to what object (record) we are dealing with. Since the Catalog Item [sc_cat_item] is referenced from the Requested Item record, we will dot-walk to that record through the cat_item field. Since your custom field is called testinfo, you may need to change it to match the actual field name (e.g.; u_testinfo). My guess is that it will say 'undefined' because you do not say the exact field name. Try changing line to be gs.print(itmObj.cat_item.u_testinfo); instead.


venkatiyer1
Giga Guru

Hi Shane,



Could you try this,




<mail_script>


    var gr = new GlideRecord("sc_req_item");


    gr.addQuery("request", ${sys_id});


    gr.query();


    template.print("Got " + gr.getRowCount() + " Records"); // log line pls remove later


    while(gr.next()) {


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


    // if the records are coming fine and the above line doesnt work   I would like to try replacing the value in paranthesis with ${gr.testinfo.getDisplayValue()}


  }


</mail_script>


With that added in, it's being completely skipped. Not even the "Got records" line is coming through.


venkatiyer1
Giga Guru

Hi Shane,



May be surround it with double quotes and check it or alternatively assign it to a local variable and then apply it in addquery. May be addquery is causing an exception with the $ in its value.



  gr.addQuery("request", "${sys_id}");