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

nthumma
Giga Guru

try this var gdt = new GlideDateTime();



and set gr.my_dateTime_field = gdt;


GlideDateTime - ServiceNow Wiki


Hi srnewbie thanks for the answer but I have tried this before it doas not work !
do you have another idea?


Abhinay Erra
Giga Sage

Instead of "gr.my_dateTime_field = gs.nowDateTime();" use this gr.setDisplayValue('my_dateTime_field', gs.nowDateTime());


Hi Abhinay thanks for the answer
I have tried this too but it doas not work !


may be another idea ?