Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

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
Giga 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
Giga 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

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

Part 15. In this video i have talked about Access Control List (ACL) in details. I have explain below. 1. Overview on ACL. 2. How to create ACL. 3. Different types of ACL. 4. How ACL works. 5. Execution order of ACL. 6. ACL Evaluation 7. Debug ACL 8. ACL Troubleshoot. 9. Real time use case live ...