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 08:14 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 08:30 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 08:33 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 08:35 AM
Yes this interesting too, thank you im gonna mark it as correct for others !

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 08:37 AM
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.