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

Did you call this email script in the notification

 

${mail_script:example_name}

 

Below is the sccrrenshot that how i am calling my email scrit 

my email script name is : Adding_Email_approver_for_Stockade

 

Its just not working

VIKASMISHRA_0-1681391121038.png

 

It should work. Please check the backend name of the email variable you are calling in your script

ITs working now, basically instaed of "Sc_cat_item" we need to glide the table "SC_Req_item".

Thanks for the help

Glad to know that 🤗