Date field value is not populating by using setValue by using client scripts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 06:26 AM
Hi Team,
I wrote a catalog client script and script include to change date format from YYYY-MM-dd to MM-dd-yyyy . Below are both catalog client script and script include.
Here the issue is script include returning the formatted date correctly but the setValue in catalog client script is not working and morover its recalling scripting include again and the values are keep changing. What wrong with below code?
OnChange Catalog client script :
var cdt = g_form.getValue('testing_date');
var ajax = new GlideAjax('test');
ajax.addParam('sysparm_name','addDateTimeAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('testing_date',answer);
Script Include :
addDateTimeAmount: function(){
gs.info('dinesh');
var firstDT = this.getParameter('sysparm_fdt'); //First Date-Time Field
var day = new GlideDate();
day.setValue(firstDT);
var formattedDate = day.getByFormat("MM-dd-yyyy");
gs.info('dineshtestresult '+formattedDate );
return formattedDate ;
}
I can able to see the info logs that the format is changing but issue is after selecting the date the script is processing multiple times and date is keep on changing randomly. This is weird 😞 .
You can find in the below image that selected date is different and alerted date value is different.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 06:55 AM
Hi Dinesh
Please refer he below link.
Please mark the answer as correct or helpful if solves your issues.
Thanks