Email Script (To print dynamic days through Email notification)

Naman Jain2412
Tera Expert

Hi, 
I have created a below script however when I am triggering notification it is showing days like that in format 14141415. Could you please let me know what is the specific issue because of which it is showing like this. 

Name of the email script :- sn_dynamic_values_renewal_date

Below is the attached code for reference: -

 

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

        var user;
        var gr = new GlideRecord('sn_compliance_policy');
        gr.addQuery("state", "draft");
        gr.query();
        while (gr.next()) {


            var u = new GlideDateTime(gr.u_next_renewal_date);
            var c = new GlideDateTime().getDate();
            var d = gs.dateDiff(c, u, true);
            var days = d / (60 * 60 * 24);
            // var days = parseInt(d,10)/(60*60*24);

         

                if (days == 15 || days == 14 ||days == 12 ||days == 10 ||days == 8 || days == 6 ||days == 4 ||days == 2||days == 0) {
                    // template.print("u_next_renewal_date" + days + " days<br/>");
                        template.print(days);

                }

            // Add your code here

        }
   
})(current, template, email, email_action, event);
 
In Notification 
This is to inform you that the ${name} is scheduled for renewal on ${u_next_renewal_date}, which is ${mail_script:sn_dynamic_values_renewal_date} days from today.

Eg :- Renewal date is scheduled on 09/07/2026

and the TEST Record is created on 09/07/2025 14:03:00

Based on the given script it is showing result as 0206101012 days as 

 

 

This is to inform you that the TEST is scheduled for renewal on 09/07/2026, which is 0206101012 days from today.

 

 

10 REPLIES 10

Mark Manders
Mega Patron

You are looping through all policies and are printing every outcome (0 2 6 10 10 12).

So you are printing the difference for every found policy. What are you exactly trying to do? 

If you are triggering it for a certain record, you could add a 'current' in there, or you aggregate through it and show the minimal dates. But the script itself is doing what you are asking: loop through the policies and print the difference in days for each policy.


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