Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Setting time value

Sneha39
Mega Guru

Got time field on table and want to set it on RITM variable. 

 

var today = new GlideDateTime();
var gr = new GlideRecord('u_sam_tb');
gr.addQuery('sys_id', current.variables.ids);
gr.setLimit(1);
gr.query();

if (gr.next()) {
var dTime = new GlideDateTime(gr.getValue('u_time'));
var dTimeStrg = new GlideDateTime(dTime.getTime().getByFormat(' HH:mm:ss'));
var Date = new GlideDateTime(today.getDate() + dTimeStrg);

}

Here var Date is not setting correct time on the RITM field.

I want to set as is time for eg it var dTime = 1:30 am it should set 1:30 am ( timezone should also not impact or change time)

1 ACCEPTED SOLUTION

Sneha39
Mega Guru

If anyone interested :

Above can be achieved by splitting date and time array and setting the value via current object.

View solution in original post

2 REPLIES 2

wildermount
Tera Expert

Try using getDisplayValue() to see if it gets you what you need, but there are many methods to gdt. 

var dTime = new GlideDateTime(gr.getValue('u_time'));

dTime.getDisplayValue(); //<< should return the current time depending on where you call it. 

Although, you may find the method you are looking for here. 

Ref: GlideDateTime ServiceNow Dev docs

Sneha39
Mega Guru

If anyone interested :

Above can be achieved by splitting date and time array and setting the value via current object.