- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 01:17 AM
Hello @Ankur Bawiskar
I have used the script include from your previous blog and client script for changing my date format on my catalog variable form for a date type field. The problem is that I am able to change date format as required but my on change client script keeps on changing the field value continuously on the form. Can you pls help on this. Thanks in advance
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 02:01 AM
you need to stop the recursion by checking the date format
something like this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(oldValue != newValue){
var isValid = getDateFromFormat(newValue,'MM-dd-yyyy') != 0;
if(!isValid){
// trigger the ajax when the format is not valid
// when the format is valid it won't trigger ajax and will avoid recursion
//Type appropriate comment here, and begin script below
var userValue = g_form.getValue('start_date');
var ga = new GlideAjax('testDateFormat');
ga.addParam('sysparm_name', 'convertDateFormat');
ga.addParam('sysparm_format', userValue);
ga.getXML(result);
function result(response) {
var answer = response.responseXML.documentElement.getAttribute('answer').toString();
g_form.setValue('start_date', answer);
}
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 03:07 AM
@Ankur Bawiskar
When tried to submit the request on catalog form it shows an error message "The following fields contain invalid value: start date and end date". This error came after changing the date format.
Can you plesae help on this..I am not able to submit a request because of this date format change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 03:13 AM
are you also changing the format for end date?
You might have to tweak the onSubmit script as well
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 03:17 AM
@Ankur Bawiskar
Yes I want to change the format of end date also. So i created a separate client script for end date variable also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 03:18 AM
@Ankur Bawiskar
On submit client should we use script to forecfully accept the date format and make the request submit.can u help on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 04:03 AM
why not add validation on change of end date itself?
share your onSubmit script
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader