UI Action: How to populate datetime field with the current datetime

carlocsa
Kilo Expert

Hi ServiceNow Gurus,

How do I populate a datetime field with the current datetime + 2 hours on submit in a UI Action?

Thank you very much.

Carlo

 

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

var dt = new GlideDateTime(); dt.addSeconds(7200); current.setValue(‘u_your_field’, dt.getValue());

put the above in the script portion portion of your UI Action.

View solution in original post

2 REPLIES 2

Jon Barnes
Kilo Sage

var dt = new GlideDateTime(); dt.addSeconds(7200); current.setValue(‘u_your_field’, dt.getValue());

put the above in the script portion portion of your UI Action.

The SN Nerd
Giga Sage
Giga Sage

Assuming your UI Action is Server Side:

current.dateTimeField = gs.hoursAgo(-2);

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022