How to insert a current date time from script to a DateTime field ?

Adil JEBLI
Mega Expert

Hi everyone,
I want to add a current dateTime to my dateTime field, in the wiki there is this way :

var gr = new GlideRecord('table_name');

gr.addQuery('some_query');

gr.query();

gr.my_dateTime_field = gs.nowDateTime();

gr.update();

but it doas not work for me !

doas anyone know how to fix this issue ?

thank you

13 REPLIES 13

Abhinay Erra
Giga Sage

It should work. It works on my instance. Are you sure the field is of type Date/Time? Are you in scoped application? Also please share the entire script.


hi,
I was wrog it works with the 2 ways !



gr.my_dateTime_field = gs.nowDateTime();



or

gr.setDisplayValue('my_dateTime_field', gs.nowDateTime());



Thank you


Abhinay Erra
Giga Sage

Glad you got this working. Use setDisplayValue() for this. Because gs.nowDateTime() gets the current date time in user's date format and time zone.


Yes this interesting too, thank you im gonna mark it as correct for others !


You cannot mark this thread as correct, because you started this as a discussion not a question. You need to change it to question to mark it as correct.