Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Way to set today to Date column with client script

matsui
Tera Contributor

Hello,

 

I want to set today to Date column with client script.
I understand that I can set it with javascript: new GlideDateTime().getDate() in default value.
But, it needs to set today, only when the value of other column is changed.
So I think that I need to use client script.
How I can set it with client script ?

 

Regards,

1 ACCEPTED SOLUTION

Kavita_Bhojane
Tera Guru

Hi @matsui ,

 

You can use onChange client script. Here, I have set "Today's Date" on change of priority. 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var today_date = new Date();
var today_date_str = formatDate(today_date, g_user_date_format);
//Type appropriate comment here, and begin script below
if (oldValue != newValue) {
g_form.setValue('u_todays_date', today_date_str);
}
}

 

Screenshot 2023-10-24 at 9.05.11 PM.png

 

Please mark my answer helpful if you find it useful.

 

Thanks,

Kavita Bhojane

View solution in original post

10 REPLIES 10

matsui
Tera Contributor

Thank you. It worked as expected.