Email Script used in the notification mail is not workings

Sami02agrawal
ServiceNow Employee
ServiceNow Employee

In my CD app there is a reminder notification that is being sent out via daily scheduled job to the approver to approver pending records. Notification is working fine. However, the link in the notification mail which takes to the approver to the pending records is not working after go live. How can I fix this? What could possibly go wrong? Here is the body of the mail

Sami02agrawal_0-1717653552541.png

 

and here is the email script

 

(function runMailScript(current, template, email, email_action, event) {
 
    var previousBatchName = "";
    var currentBatchName = "";
    var count = 1;
    var tableData = JSON.parse(event.parm2);
 
 
    if (tableData.length > 0) {
        template.print("<style>table, th, td {border:1px solid black;border-collapse:collapse;padding:10px}</style>");
        template.print("<table><tbody><tr style=background-color:rgb(17,44,64);color:white><th>Batch Name</th><th>Total no. of records</th><th>Date of Request</th><th>Assigned to</th></tr>");
        var i = 0;
        while (i < tableData.length) {
         
 
            currentBatchName = tableData[i].batch_name.toString();
            
            if (previousBatchName != currentBatchName) {
 
             count=getTotalRecords(currentBatchName);
                var batchLink = "<a href='/x_snc_test_run_b_0_npi_approval_tracker_list.do?sysparm_query=batch_folder_name=" + tableData[i].batch_name.toString() + "'>" + tableData[i].batch_name.toString() + "</a>";
               
                template.print("<tr style=border 1px solid black><td>" + batchLink + "</td><td>" + count + "</td><td>" + tableData[i].date_of_request + "</td><td>" + tableData[i].assigned_to.toString() + "</td></tr>");
                //reciepient.push(tableData[i].assigned_to);
                
            }
 
            previousBatchName = currentBatchName;
 
            i++;
 
        }
        template.print("</tbody></table>");
    }
    email.addAddress("cc", "revenue.products@servicenow.com");
 
function getTotalRecords(batchName)
{
var result=0;
var j=0;
while(j<tableData.length)
{
if(tableData[j].batch_name==batchName)
{
result++;
}
j++;
}
 
return result;
}
 
 
 
})(current, template, email, email_action, event);

 

4 REPLIES 4

Mark Manders
Mega Patron

Are you really using an email script with spaces in the name?

And did this script work on pre-prod?

What is the output you do get?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Yes it was working in Dev instance. Here is the notification

Sami02agrawal_1-1718100122920.png

 

Community Alums
Not applicable

Hi @Sami02agrawal ,

 

Can you please take a look into the URL of the notification. Basically right click on the link in the email and copy and past it in a notepad and check the URL.

I suspect its not able to construct link properly.

Additionally please replace the code for the batchLink with the below one-

var batchLink = "<a href='https://" + gs.getProperty("instance_url") + "/x_snc_test_run_b_0_npi_approval_tracker_list.do?sysparm_query=batch_folder_name=" + tableData[i].batch_name.toString() + "'>" + tableData[i].batch_name.toString() + "</a>";

 

Validate the system property instance_url

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

Sami02agrawal
ServiceNow Employee
ServiceNow Employee

This is the link I can see. 

 

\x_snc_test_run_b_0_npi_approval_tracker_list.do?sysparm_query=batch_folder_name=24 03 Enterprise-Premier Support Account Management v2