The CreatorCon Call for Content is officially open! Get started here.

Get today's date in a client script?

arobertson
Tera Guru

Hi All,

 

I'm trying to populate a read only field with today's date in the format of "28-May-2014" but notice that i cannot use any .gs functions?

1 ACCEPTED SOLUTION

akt_snow
Giga Expert

Hi Alex,



You refer to the below wiki link.


Set Current DateTime In Field - ServiceNow Wiki



Thanks,


Avneet


View solution in original post

10 REPLIES 10

Dude the Client Script is totally wrong



the right is :



var ajax = new GlideAjax('MyDayAjax');
          ajax.addParam('sysparm_name','MyDayDate');
          ajax.getXML(SetValues);



    function SetValues(response) {
          var answer = response.responseXML.documentElement.getAttribute("answer");
          g_form.setValue('u_date_sent',answer);


}


Jim Coyne
Kilo Patron

I was just wondering when you were setting the date?   Is it just for when a new record is created?   If so, you can either set the default value or set it on insert via a Business Rule, both using gs methods.



Or is it when another field is changed?



I try to avoid client scripts whenever possible.


yea, I cut out the top part of the client script, it is on change client script, and there is a if condition so it only runs the script include when the field is changed to a certain value.   I could have done an on submit business rule, but the end users liked seeing the time/date for this field before they submitted.


Hi Jim,



I'm setting the date "onChange" of a choicelist.


deepakvednegi
Giga Contributor

Script Include will do this for you.



https://wiki.servicenow.com/index.php?title=Set_Current_DateTime_In_Field



For further functions in date time, you can follow this link



Client Script Date/Time Functions