Client script not taking effect -Display date

PatriciaA987250
Tera Expert

Hi,

i've created a client script to set date on one of the form field. When i tested in the new project workspace it is not taking any effect. Could someone provide step-by-step guide on how to achieve this.

 

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   var currentDate=new Date();
   g_form.setValue('field_name', currentDate);
}

 

client script.png

 

form field.png

1 ACCEPTED SOLUTION

palanikumar
Mega Sage

Try this script

function onLoad() {
   //Type appropriate comment here, and begin script below
   var currentDate=new Date();
   var currentDateFormated = formatDate(currentDate, g_user_date_format);
   g_form.setValue('field_name', currentDateFormated);
}
Thank you,
Palani

View solution in original post

2 REPLIES 2

palanikumar
Mega Sage

Try this script

function onLoad() {
   //Type appropriate comment here, and begin script below
   var currentDate=new Date();
   var currentDateFormated = formatDate(currentDate, g_user_date_format);
   g_form.setValue('field_name', currentDateFormated);
}
Thank you,
Palani

Runjay Patel
Giga Sage

Hi @PatriciaA987250 ,

 You can use below script to set the current date.

var today_date = new Date();
var today_date_time_str = formatDate(today_date, g_user_date_time_format);

g_form.setValue('your_field_name',today_date_time_str);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------