Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help with mail script

Thomas99
Tera Contributor

Hi,

 

I have a date field in the form (date_birth) which is in YYYY/MM/DD format. 

 

I want this to be changed to DD/MM/YYY format in an email notification. 

 

Can someone please help me with the mail script. One I created doesn't render the desired result. 

1 ACCEPTED SOLUTION

@Thomas99  Here is my testing result, i have tested on my personal instance.

Attached screenshot for your reference, it working perfectly at my end.

 

testing record.PNGtestign email script.PNGTesting data.PNG

View solution in original post

6 REPLIES 6

Harsh Vardhan
Giga Patron

Hi @Thomas99 You can try to use below script.

 

var dt = "2024/01/12";  // Change here with your field name 
var gdt1 = new GlideDate();
gdt1.setDisplayValue(dt);
var fDate = gdt1.getByFormat("dd/MM/yyyy");     
gs.print(fDate);  // Use template.print to print it on notification

 Hope it will help you.

 

Thanks,

Harsh 

Mail script sample code .

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
		/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
		/* Optional GlideRecord */ event) {
	
	
        var gdt1 = new GlideDate();
        gdt1.setDisplayValue(current.<FieldName>); // Add your field Name
        var fDate = gdt1.getByFormat("dd/MM/yyyy");  
	
	template.print(fDate);
		

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

 

Thanks,

Harsh

Hi Harsh,

 

I used the mail script you provided  and replaced the field name, however, I'm getting today's date than the actual date that is entered in the field 

 

 gdt1.setDisplayValue(current.date_of_birth); // Add your field Name

@Thomas99  Here is my testing result, i have tested on my personal instance.

Attached screenshot for your reference, it working perfectly at my end.

 

testing record.PNGtestign email script.PNGTesting data.PNG