Email Script to populate different variables based on different catalog

Appy2
Tera Contributor

Hi All,

My requirement is to create one notification for 2 different catalogs and notification should contain variable of particular catalog item.For example i have 2 catalogs:

Catalog 1(Server Request ) have fields "Server 1,Server 2 and Server 3"

Catalog 2(database Request ) have field "database 1,database 2 and database 3"

notifications should be triggered once RITM get created and this notification should contains "Server 1 and Server 2" if Catalog 1 gets submitted and "database 1,database 2" should be populated it Catalog 2 gets submitted.

how we can achieve this with one email script?

If any idea please share with me.

Thanks in Advance.

 

1 ACCEPTED SOLUTION

Ankur Swami
Tera Guru

Hi,

You can write the email script and call it in your notification.

 

Name = "multiple_cat_item_example"

 

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

        // Add your code here
        var gr = new GlideRecord('sc_cat_item');
        gr.addQuery('sys_id', current.sys_id);
        gr.query();
        if (gr.next())

        {
            if (gr.cat_item == 'sys_id_of_catalog1') {
                template.print(current.variables.server_1);
                template.print(current.variables.server_2);
                template.print(current.variables.server_3);
                email.setSubject("For catalog item 1");
            }

           else  if (gr.cat_item == 'sys_id_of_catalog2') {
                template.print(current.variables.database1);
                template.print(current.variables.database2);
                template.print(current.variables.database3);
                email.setSubject("For catalog item 2");
            }
        }

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

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

 

Now call the email script in the notification What it will Contain >> Message HTML

${mail_script:multiple_cat_item_example}

View solution in original post

10 REPLIES 10

Ankur Swami
Tera Guru

Hi,

You can write the email script and call it in your notification.

 

Name = "multiple_cat_item_example"

 

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

        // Add your code here
        var gr = new GlideRecord('sc_cat_item');
        gr.addQuery('sys_id', current.sys_id);
        gr.query();
        if (gr.next())

        {
            if (gr.cat_item == 'sys_id_of_catalog1') {
                template.print(current.variables.server_1);
                template.print(current.variables.server_2);
                template.print(current.variables.server_3);
                email.setSubject("For catalog item 1");
            }

           else  if (gr.cat_item == 'sys_id_of_catalog2') {
                template.print(current.variables.database1);
                template.print(current.variables.database2);
                template.print(current.variables.database3);
                email.setSubject("For catalog item 2");
            }
        }

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

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

 

Now call the email script in the notification What it will Contain >> Message HTML

${mail_script:multiple_cat_item_example}

Thank you Ankur for your response.

Few changes in the code and it worked for me.

I am also trying to send email to different users based on catalog

email.setReplyTo(current.variables.owner);

but its not triggering to the owner.

Can you please help me here

 

Hi,

*is the Owner filed referring to 'sys_user' table?

If this is the case then modify the line according to below code:

email.setReplyTo(current.variables.owner.email);

 

If i was able to help you and you achieved you implement this then please mark the content as "Correct Answer", That can other community users to find their similar answer easily.

 

Thanks,

Ankur

Hi Ankur,

yes i tried this also but no luck

 email.setReplyTo(current.variables.owner.email);