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.

How to get the month and year of a date field using onSubmit Client script?

Yesh
Tera Contributor

Hi Team,

I have a requirement like onsubmit of the form, i need to display the month and year of the date field: Post date on the form as a info message using OnSubmit Client script. How to achieve this?

Any suggestions will help.

Thanks

1 ACCEPTED SOLUTION

Jan Cernocky
Tera Guru

How about simply getting value from the field and running substring function on that? 🙂

	var date = g_form.getValue('post_date');
	var year = date.substring(0,4);
	var month = date.substring(5,7);
	g_form.addInfoMessage('Year: ' + year + ' / Month: ' + month);

 

find_real_file.png

View solution in original post

1 REPLY 1

Jan Cernocky
Tera Guru

How about simply getting value from the field and running substring function on that? 🙂

	var date = g_form.getValue('post_date');
	var year = date.substring(0,4);
	var month = date.substring(5,7);
	g_form.addInfoMessage('Year: ' + year + ' / Month: ' + month);

 

find_real_file.png