Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Notification section is only displayed if the approval is related to a RITM

Emine
Tera Contributor

I have a notification running on sysapproval_approver table. I want to display a section in the email onöy when the approval is related to a RITM.

 

Fields I want to show in the notification:

Item (cat_item on RITM)

Requested For (requested_for on RITM)

and I also want to show the Variables Section of the RITM.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Emine 

if you are talking about the OOTB notification on sysapproval_approver then

-> you need to create an email script and include that in your email body

-> in email script check what's the source table

I hope you know how to include email script in email body

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

    var sourceTable = current.source_table;
    if (sourceTable == 'sc_req_item') {
        // add your logic to print
        var ritmSysId = current.sysapproval;
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("sys_id", ritmSysId);
        gr.query();
        if (gr.next()) {
            template.print("Item: " + gr.cat_item.name);
            template.print("Requested For: " + gr.request.requested_for.name);

            // add logic to print variables you want
            var variables = gr.variables.getElements();
            for (var i = 0; i < variables.length; i++) {
                var question = variables[i].getQuestion();
                var label = question.getLabel();
                var value = question.getDisplayValue();
                if (label != '' && value != '') {
                    template.print(label + " = " + value + "<br/>");
                }
            }
        }
    }

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

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

4 REPLIES 4

GlideFather
Tera Patron

Hi @Emine,

 

for displaying the variables you might need the notification email script to be written as teh variables are stored in different table then the [sysapproval_approver].

 

Please share what you created to review it

_____
Answers generated by GlideFather. Check for accuracy.

Nilesh Pol
Kilo Sage

@Emine To display a specific section in an approval email only when it relates to a Request Item (RITM) and include RITM details and variables, you should use an Email Script. This approach allows you to check if the sysapproval field points to an sc_req_item table and retrieve the associated variables efficiently.

 

 

Tanushree Maiti
Kilo Patron

Hi @Emine 

 

To Display  RITM related info like item, Requested For, and Variables etc. in an approval notification running on the sysapproval_approver table, you must use Email Scripts to check if the approval is related to a RITM and fetch those specific details. 

 

Sample code you will get in this post:

https://www.servicenow.com/community/developer-forum/how-do-i-get-an-ritm-field-to-show-on-the-appro...

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@Emine 

if you are talking about the OOTB notification on sysapproval_approver then

-> you need to create an email script and include that in your email body

-> in email script check what's the source table

I hope you know how to include email script in email body

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

    var sourceTable = current.source_table;
    if (sourceTable == 'sc_req_item') {
        // add your logic to print
        var ritmSysId = current.sysapproval;
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("sys_id", ritmSysId);
        gr.query();
        if (gr.next()) {
            template.print("Item: " + gr.cat_item.name);
            template.print("Requested For: " + gr.request.requested_for.name);

            // add logic to print variables you want
            var variables = gr.variables.getElements();
            for (var i = 0; i < variables.length; i++) {
                var question = variables[i].getQuestion();
                var label = question.getLabel();
                var value = question.getDisplayValue();
                if (label != '' && value != '') {
                    template.print(label + " = " + value + "<br/>");
                }
            }
        }
    }

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

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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