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

akt_snow
Giga Expert

Hi Alex,



You refer to the below wiki link.


Set Current DateTime In Field - ServiceNow Wiki



Thanks,


Avneet


johnram
ServiceNow Employee
ServiceNow Employee

The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: Date and Time Fields



Visit http://docs.servicenow.com for the latest product documentation


So, the wiki is sadly dead (despite still being the best source for SN answers, while I've had about a 7% success rate getting anything out of docs), and I appreciate you trying to link to docs to find the answer there.   But your "Date and Time Fields" link returns an error, and I cannot find whatever you're trying to point to via the docs search.



Docs means well, but man is it frustrating to use.


mduluk
Giga Expert

Here is the script include, it needs to be client callable.



var MyDayAjax = Class.create();



  MyDayAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {



      MyDayDate: function() {


          return gs.now();


      }


});


and here is the client script



      var ajax = new GlideAjax('MyDateTimeAjax');
          ajax.addParam('sysparm_name','nowDateTime');
          ajax.getXML(SetValues);

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


}



u_date_sent is the field that I was setting the date for.