Email script & Notification

rahul122
Tera Contributor

My requirement is in the notification if i have 5 catalog items in my name all the catalog items name should be populated in the email body notication.

 

I have created the notification from the sys_user table and it is triggering by using event that is triggering emails  as expected but i m not able to populate catalog items name in my email notification.

I have created an email script to retrieve and list the catalog item names and included that script in the notification but it is not working 

 

Email script that i have created:

{

    var list = '';

    var gr = new GlideRecord('sc_cat_item');
    gr.addQuery('active', 'true');
    gr.addQuery('owner', current.sys_id);
    gr.query();
    while (gr.next()) {
        list += '-' + gr.getDisplayName('name') + '\n';
    }
    return list;

 

 

 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@rahul122 

when you use email script you have to print it using template.print()

why are you returning the value?

are you calling some script include and then returning that value?

you can simply use this in email script to print comma separated catalog item names

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var itemArray = [];
    var itemRec = new GlideRecord('sc_cat_item');
    itemRec.addActiveQuery();
    itemRec.addQuery('owner', current.getValue('sys_id'));
    itemRec.query();
    while (catGr.next()) {
        itemArray.push(itemRec.name.toString());
    }
    template.print('Catalog items are: ' + itemArray.toString());

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@rahul122 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

rahul122
Tera Contributor

Hi ,

 

My issue is resolved now thank you all for the response. Will post in some time how it got resolved