- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 04:59 AM
I want to set today's date field automatically , when i opened the new form and same as with time so i have created two seperate fields for date and time those are need to be filled automatically when i open the new form could any one please help me....?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2018 12:33 AM
If you want to use current time and date on different tables, the use this script include:
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor,
{
nowDateTime: function ()
{
return gs.nowDateTime(); }
});
call this S.I in onload client script:
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(function ()
{
g_form.setValue('put your field name here', ajax.getAnswer());
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 06:15 AM
Hi Surya,
The point of the default value is to take that value when you create a new record. Just like I can default the caller on an incident to be "me", when you open it up, it will be your name that appears in that field. That's the purpose of the default value.
If you open a new record on your custom table (or whatever it is we were talking about at the top of this conversation) the default value will put in today's date for the default value on the date field if you use the line of code I indicated. Tomorrow it will show tomorrow's date.
Once the record is saved, the value stays locked where it was when the form was created (unless someone manually changes it.)
I hope that makes sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 06:29 AM
Ya I have understood but it's not at all working ....?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 06:30 AM
Is this a variable on a catalog item or a field on a table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 02:45 AM
ya i mentioned in above right, It is a field in table and ofcourse i have wrote server side script but it 's not working can you suggest script please

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2017 05:55 PM
I was able to set a separate date and time field with a display business rule and client script like this:
Business Rule
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.start_date = new GlideDate().getDisplayValue();
g_scratchpad.start_time = new GlideTime().getDisplayValue();
})(current, previous);
Client script:
function onLoad() {
if (g_form.getValue('start_date') == '') {
g_form.setValue('start_date', g_scratchpad.start_date);
}
if (g_form.getValue('start_time') == '00:00:00') {
g_form.setValue('start_time', g_scratchpad.start_time);
}
}