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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 07:26 AM
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
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 07:32 AM
try this var gdt = new GlideDateTime();
and set gr.my_dateTime_field = gdt;
GlideDateTime - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 08:06 AM
Hi srnewbie thanks for the answer but I have tried this before it doas not work !
do you have another idea?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 07:37 AM
Instead of "gr.my_dateTime_field = gs.nowDateTime();" use this gr.setDisplayValue('my_dateTime_field', gs.nowDateTime());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 08:08 AM
Hi Abhinay thanks for the answer
I have tried this too but it doas not work !
may be another idea ?