Add hours to the opended_at field and display in a new field

Matt25
Giga Guru

Hi all, 

I hope this is an easy one to get solved,

Im after populating a field (u_cpc_date_time) with the time of '2 hours' after the opened_at time when a ticket is opened,

so...if a ticket was opened at 13:00, the 'u_cpc_date_time' field would display 15:00, im not sure if this is a business rule or a client script so any help would be great.

Thanks

Matt

 

1 ACCEPTED SOLUTION

Matt25
Giga Guru

Full solution,

var gdt = new GlideDateTime(current.opened_at);
gdt.addSeconds(7200);
current.u_cpc_date_time=gdt;

View solution in original post

7 REPLIES 7

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

It could be either, but by the looks of it, it should be a business rule that runs on insert.

-Anurag

 

-Anurag

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

create a Business Rule and add the following code as example:

var gdt = new GlideDateTime(current.opened_at);
gdt.addHours(2);
current.u_cpc_date_time=gdt;

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

Thanks for your reply, this is populating the field but with the exact same time as the opened_at time, no difference

Thanks Alberto