- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:45 AM
Hi All,
I have a requirement where i have to auto populate a date field based on the field ('information' - field type is checkbox). If the checkbox is checked then populate today date in the date field.
How can i achieve this, please help.
Thanks in Advance,
SD.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:52 AM
Please check this as well.
Name: Set Current Date/Time In Field
Type: Client Script
Table:
Description: You can use the following two lines to set the current date and time in a date/time field. This bypasses the problem of getting the value into the proper format and proper timezone:
Parameters:
Script: For more information on running Server Side Script with the client please refer to GlideAjax.
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(function () { g_form.setValue('put your field name here', ajax.getAnswer()); });
System Script Include
// Be sure the "Client callable" checkbox is checked var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, { nowDateTime: function () { return gs.nowDateTime(); }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:52 AM
Please check this as well.
Name: Set Current Date/Time In Field
Type: Client Script
Table:
Description: You can use the following two lines to set the current date and time in a date/time field. This bypasses the problem of getting the value into the proper format and proper timezone:
Parameters:
Script: For more information on running Server Side Script with the client please refer to GlideAjax.
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(function () { g_form.setValue('put your field name here', ajax.getAnswer()); });
System Script Include
// Be sure the "Client callable" checkbox is checked var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, { nowDateTime: function () { return gs.nowDateTime(); }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:54 AM
Hi snow123@,
Please check this http://wiki.servicenow.com/index.php?title=Set_Current_DateTime_In_Field#gsc.tab=0
If you found this helpful, please mark it as "helpful/Correct Answer" Or Like it.
Regards,
Saikiran Guduri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 11:30 AM
On client side only you can get today date with below script, check if it is useful.
var dFormat = g_user_date_format; |
var tdayDate = formatDate(new Date(),dFormat);
g_form.setValue('todayDate', tdayDate);
write this 3 lines of code in onChange client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2021 01:16 AM
can anyone help me for understanding the logic.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2021 01:58 AM
Go through the below article
https://servicenowguru.com/scripting/client-scripts-scripting/client-side-dates-in-servicenow/