How to populate one RITM's variable value in email notification

VIKAS MISHRA
Tera Contributor

We have create one notification which will be triggered if RITM is not approved after 5 days. hence in this notification we are triggering some dynamic values also and for that created one email script where the code is already we are getting the dynamic values from the raised RITM and populating in the notification, 

All the dnamic values are basicalled we getting from the different variables of the RITM and this code is already wqritten. 

Now i just need to make some changes in email script so that it will populate variable "apprpoval's name" as the "Dear approver : Username(apprpoval's name) in the notification. please suggest how can i populate this approver name.

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

    // Add your code here
    template.print("Summary of Requested items:<br />");
    var item = new GlideRecord("sc_req_item");
    item.addQuery("sys_id", current.sys_id);
    item.query();
    while (item.next()) {
        template.print(item.number + ":  " + item.cat_item.getDisplayValue() +" Request<br />");
        template.print("    Details:<br />");
        var keys = [];
        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() + "<br />");
            }
        }
    }

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

 

VIKASMISHRA_1-1681386850429.png

 

 

VIKASMISHRA_2-1681386874138.png

 

VIKASMISHRA_3-1681386915095.png

 

 

1 ACCEPTED SOLUTION

Amrit4
Tera Guru

 

Please write an email script & call it in your notification.

 

Name = "example_name"

(function runMailScript(current, template, email, email_action, event) {
        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);


Then call this email script in the notification 

${mail_script:example_name}

 

View solution in original post

13 REPLIES 13

Amrit4
Tera Guru

 

Please write an email script & call it in your notification.

 

Name = "example_name"

(function runMailScript(current, template, email, email_action, event) {
        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);


Then call this email script in the notification 

${mail_script:example_name}

 

Do i need to create a separate email just for this or i can merge your script somwhere in my email script only 

You can merge it somewhere.

Please be kind enough to mark my answer correct if this works for you

I have created another email script and pasted your code in it but iots not working, please suggest

(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 == '7c40a1d41b251510680a0e9cdc4bcbf4') {
                template.print(current.variables.approvers_e_mail_address);
            
            }
        }

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

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