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.

suryapulletikur
Kilo Contributor

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....?

1 ACCEPTED SOLUTION

rambo1
Tera Guru

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());
});

View solution in original post

26 REPLIES 26

Chuck Tomasi
Tera Patron

Try this: go to the dictionary entry (right click the field label and click Configure Dictionary)



Set the default value field to this:



javascript:new GlideDateTime().getDisplayValue()


If we set default value to the variable it shows the same right that is not the case na...?


i was asking to set the field automatically when i open the new form. it should take date and time from system . so can you please be specific...?


Sorry, I didn't quite understand this part.



If we set default value to the variable it shows the same right that is not the case na...?



I apologize, I forgot that you had two separate fields. In the date field, the default value should be:



javascript:new GlideDate().getDisplayValue();



and the time field should be



javascript:new GlideTime().getDisplayValue();



You said i need that to set default value to this javascript:new GlideDateTime().getDisplayValue() right ..? but as per my view the default value option is to keep the value whatever you want to set when form opens...


but, my question is to set that time automatically when you open the form now suppose if i opened right now it should be visible in that field at particular time ...? is that possible...?