- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2014 07:28 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2014 08:13 AM
Hi Alex,
You refer to the below wiki link.
Set Current DateTime In Field - ServiceNow Wiki
Thanks,
Avneet

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2017 07:39 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2014 08:21 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2014 08:25 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2014 08:25 AM
Hi Jim,
I'm setting the date "onChange" of a choicelist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2014 08:27 AM
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