EMAIL NOTIFICATION

AkashKushwah
Tera Contributor

Hi Everyone ,

I have written an email notification with email script which show the current year in signature like @2025 for this year how to check for next year . I have attached my email script and notification below . can anyone check my code is it correct or not .

Thank you

3 ACCEPTED SOLUTIONS

GlideFather
Tera Patron

Hi @AkashKushwah,

 

just add +1 as seen below: 

 

var currentYear = new Date().getFullYear();
var nextYear = currentYear + 1;
gs.info(nextYear);

 

KamilT_0-1752757550576.png

 

 

———
/* If my response wasn’t a total disaster ā†™ļø ⭐ drop a Kudos or Accept as Solution āœ… ā†˜ļø Cheers! */


View solution in original post

Shaik Dimple
Tera Expert

Hi @AkashKushwah ,

 

This script may help, it prints the next year dynamically in the email signature:

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

 
    var gdt = new GlideDateTime();
    var curYear = gdt.getLocalDate().getYear(); // safely gets current year as number
    var nextYear = curYear + 1;

  
    template.print("@" + nextYear);

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

 Screenshot 2025-07-17 185539.pngScreenshot 2025-07-17 185525.png

View solution in original post

Hi @AkashKushwah 
my response was the same and I replied earlier than the accepted one, can you please tell me why did you decide to accept this solution and not mine? thank you

———
/* If my response wasn’t a total disaster ā†™ļø ⭐ drop a Kudos or Accept as Solution āœ… ā†˜ļø Cheers! */


View solution in original post

6 REPLIES 6

GlideFather
Tera Patron

Hi @AkashKushwah,

 

just add +1 as seen below: 

 

var currentYear = new Date().getFullYear();
var nextYear = currentYear + 1;
gs.info(nextYear);

 

KamilT_0-1752757550576.png

 

 

———
/* If my response wasn’t a total disaster ā†™ļø ⭐ drop a Kudos or Accept as Solution āœ… ā†˜ļø Cheers! */


Tushar
Kilo Sage
Kilo Sage

Hi @AkashKushwah  I think it won’t automatically switch to 2026 unless you modify the logic to handle the next year.

 

(function runMailScript(current, template, email, email_action, event) {
    // Get the current year
    var currentYear = new Date().getFullYear();
    // Optionally set next year for testing or future use
    var nextYear = currentYear + 1; // e.g., 2026
    template.print(nextYear); // Use nextYear instead of currentYear for 2026
})(current, template, email, email_action, event);

 

HTML - 

Hi ${caller_id},
I have create a new incident record with the current/next year
Description: ${description}
Priority: ${priority}
Short description: ${short_description}
Best Regards,
Support Team
ServiceNow @ ${mail_script:NextYear}
 
Thanks,
Tushar

AkashKushwah
Tera Contributor

Yes , you are right but how to switch automatically like 2026,2027 or 2028. If you have any idea please let me know.

Community Alums
Not applicable

It will automatically fetch current year as 2026 when this code will run next year, no need to add any logic to increase the year for every subsequent year.