Need help in Business Rule Scripting

Admin7267
Kilo Sage

I have written a Business Rule to create an Announcement when Incident priority changes to P1. Everything is working fine except one field in Announcements table. There's a field called From in the record but its setting date and time as 2 hours from current date and time

 

Inc updated at 24-05-2024 18:25:43 and From is set to 24-05-2024 20:25:43, which should be 24-05-2024 18:25:43

 

Admin7267_0-1716568469914.png

 

gr.setValue('from', gs.nowDateTime()); is used to set the From value, how to fix this and set current date and time in that field
3 REPLIES 3

Gangadhar Ravi
Giga Sage
Giga Sage

You can select whether you want time in UTC/GMT or you want time in user time zone as they can be different

To get time you see on incident form, use Local time code as shown below

 

var gdt = new GlideDateTime();
gs.info(' 1. UTC Time: ' + gdt.getValue());
gs.info('2. Local Time in user time zone: ' + gdt.getDisplayValue());

Vengadeshgiri
Tera Contributor

Hi @Admin7267 ,

 

You can set directly the value of the field

Sample code:

var date=new GlideDateTime();

gr.<Your field backend name>=date.

 

Regards

Vengadesh

Community Alums
Not applicable

Hi @Admin7267 ,

Please try to use below script 

var dateTime = new GlideDateTime();
gs.info('Check' + dateTime.getDisplayValue());


Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak