Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to get the time and date in CET time zone in scoped application

Sai25
Tera Guru

Hi All,

I would like the date and time to be converted in Scoped application below code is not working can you please help me.

var grIncident = new GlideRecord('incident');
if (grIncident.get('sys_id', 'e8bfe5eac380cb9896985630a00131a2')) {
    var gdt = new GlideDateTime(grIncident.opened_at);
    var gsdt = new GlideScheduleDateTime(gdt);
    gsdt.setTimeZone("CET");
    var cetTime = gsdt.getGlideDateTime().getDisplayValue();
    gs.info("Incident opened time in CET: " + cetTime );

}
The above Incident record created on the 2026-04-07 21:15:06 and output I am getting is Incident opened time in CET: 2026-04-07 19:15:06 (Actually it should be 17:45:06)
 
 
Thanks,
Sai.
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Sai25 

this works in scoped app

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "IST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime)

gs.info("Converted Time: "+gdtConvertedDateTime);

55.png

💡 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

14 REPLIES 14

Ankur Bawiskar
Tera Patron

@Sai25 

this works in scoped app

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "IST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime)

gs.info("Converted Time: "+gdtConvertedDateTime);

55.png

💡 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

Hi Ankur,

 

The above code is working fine but now the issue when I try to return multiple values then time zone is not converting.

 

Description and date: Then time is not converting. (2026-04-08 08:25:16Hello)

var non_CET = fd_data.trigger.current.opened_at;
var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime(non_CET)).convertTimeZone("UTC", "CET");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime);

var final=gdtConvertedDateTime;
var description="Hello";
return final+description;
 
Date: This is converting and getting the output. (2026-04-08 10:25:16)
var non_CET = fd_data.trigger.current.opened_at;
var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime(non_CET)).convertTimeZone("UTC", "CET");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime);
return gdtConvertedDateTime;
Can you please help me.
Thanks,
Sai.

@Sai25 

Glad to know that my script worked fine for you.

Would you mind marking my response as correct and close the thread?

The discussion can continue on closed thread as well.

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

@Sai25 

what debugging did you do?

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

@Ankur Bawiskar ,
Instead of hardcoded I tried to return the data through the script. Now I am trying to update the field and then call the field in message variable..

 

Thanks,

Sai.