Need to add email button in RITM

suuriyas
Tera Contributor

HI Community,

 

I need to create a email button in RITM (similar to we have in inc) on click the email reply to, to subject and body needs to be populate

Subject will be short desc of the ritm and in body should have the variable details 

suuriyas_0-1751263641357.png

 

Like this i want to add email in ritm

 

How can we achieve this

1 ACCEPTED SOLUTION

@suuriyas 

it worked for me.

Since your email client template is on RITM update this line -> you should query with sys_id

    ritmRec.addQuery('sys_id', current.sys_id);
 

Output:

AnkurBawiskar_0-1751454626091.png

 

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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

you need to enable email_client=true in Collection type Record on RITM table

AnkurBawiskar_0-1751264110556.png

 

Then configure email client template on RITM table similar to incident table

check this link on how to include variables in email client template

Syntax is {current.variables.variableName} in email body

Populate a Variable value from RITM into an Email Client Template 

AnkurBawiskar_1-1751264132591.png

 

Output:

I configured this email client template

AnkurBawiskar_1-1751264927719.png

 

This is the Output

 

AnkurBawiskar_0-1751264898455.png

 

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

HI @Ankur Bawiskar ,

 

Thanks for the reply.

For a particular catalog item variable we can manually do this by adding current.variables.variable_name

but those variables are not going to be there in different catalog items right?

For example Variable A is present in X catalog but that variable A wont be there in Y catalog.

 

How we can achieve this dynamic thing

@suuriyas 

you can call email script and there you can write logic to fetch variables dynamically.

Simply create email script and call it using normal syntax

${mail_script:EmailscriptName}

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

HI @Ankur Bawiskar ,

 

I tried creating a mail script:

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

var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addQuery('request', current.sys_id);
ritmRec.query();
if (ritmRec.next()) {
    var vs = new GlobalServiceCatalogUtil().getVariablesForTask(ritmRec, true);
    for (var i = 0; i < vs.length; i++) {
        var isMRVS = lbl = vs[i].multi_row + "";
        var lbl = vs[i].label + "";
        var dis = vs[i].display_value + "";
        var visible = vs[i].visible_summary + "";
        if (isMRVS == 'true') {
            var vArr = vs[i];
            template.print("<div>" + "<strong>" + lbl + "</strong></div><hr>");
            for (var j = 0; j < vArr.table_variable.length; j++) {
                template.print("<div><strong>Row: </strong>" + (j + 1) + "</div>");
                var tblArr = vArr.table_variable[j];
                for (var k = 0; k < tblArr.length; k++) {
                    var mrvslbl = tblArr[k].label + "";
                    var mrvsdis = tblArr[k].display_value + "";
                    if (mrvslbl != '' && mrvsdis != '' && mrvsdis != 'false') {
                        template.print("<div>" + "<strong>" + mrvslbl + "</strong>" + ": " + mrvsdis + "</div>");
                    }
                }
                template.print("<hr>");
            }
        } else {
            if (lbl != '' && dis != '' && dis != 'false' && visible == 'true') {
                template.print("<div>" + "<strong>" + lbl + "</strong>" + ": " + dis + "</div>");
            }
        }
    }
}

})(current, template, email, email_action, event);
 
and used it in email client template but it is not working suuriyas_0-1751453424071.png