- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 04:17 AM
I have requirement like in change request , while change manager is approving the change request
if proposed start date or proposed end date is changed that time, i need to throw a error message.
I need to do this scenario in onsubmit client script.
I got the proper query, but these proposed date change am having the problem.
using get value i got the proposed start date or proposed end date in a variable.
But in need to set new value of proposed start date != old value of proposed start date
or newvalue of proposed end date != old value of proposed end date.
How to achieve this in client script onsubmit?
Please help.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 01:08 AM
Hi Anburaj,
Good Day!
function onSubmit() {
var approver = g_form.getValue('approver');
if(approver != ''){
validateTravelEndDate();
return false;
}
else{
return true;
}
}
//Helper function which calls a AJAX script include called "ClientDateTimeUtils" which gives the response in a callback where i am deciding whether to submit the form or not based on the status of days result.
function validateTravelEndDate() {
var startDate = g_form.getValue('proposed_start_date'); //First Date/Time field
var endDate = g_form.getValue('proposed_end_date'); //Second Date/Time field
var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils'); // This is the script include which can be used for date validation.
ajax.addParam('sysparm_name', 'getDateTimeDiff');
ajax.addParam('sysparm_fdt', startDate);
ajax.addParam('sysparm_sdt', endDate);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(checkDateDiff);
}
// callback function where deciding to go ahead or not with form submission.
function checkDateDiff(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer <= 0) {
alert("Proposed End date must be after Proposed Start date.");
g_form.setValue('proposed_end_date', '');
g_form.showFieldMsg('proposed_end_date', 'Please provide a future date', 'error');
return false;
} else {
g_form.submit(); // This has some issue as it's going in the infinite loop and if we just return true/false from here as it's asynchronous call , it's not handled by the onSubmit function
}
}
PS: hit correct/helpful....if it helps
Thanks,
Priyanka R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2017 09:38 PM
Yes.. you are right. But i need to have this function when clicking the approver button. So it need to be in onsubmit.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 12:11 AM
Hi Anburaj,
Why not we can have GlideAjax to fetch the old date from table and then validate with new provided date when user tries to submit the form (using onSubmit Client Scripts), if it matches then allow user to submit the form if not then terminate the form submission?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 06:32 AM
Hi Anburaj,
It would seem more appropriate to make the start/end date read-only during the approval process if you don't want them changing it. You can do this with a UI policy or data policy.
One of the rules of good user design - Prevent users from doing something they shouldn't - don't let them do something and them scorn them for doing it when they should not have.
Updated 2018-12-14: Replaced Wiki link with Docs link
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2017 09:39 PM
NO. it need to be editable. while try to approve if they change the values of that field and then the error message need to show.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 01:08 AM
Hi Anburaj,
Good Day!
function onSubmit() {
var approver = g_form.getValue('approver');
if(approver != ''){
validateTravelEndDate();
return false;
}
else{
return true;
}
}
//Helper function which calls a AJAX script include called "ClientDateTimeUtils" which gives the response in a callback where i am deciding whether to submit the form or not based on the status of days result.
function validateTravelEndDate() {
var startDate = g_form.getValue('proposed_start_date'); //First Date/Time field
var endDate = g_form.getValue('proposed_end_date'); //Second Date/Time field
var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils'); // This is the script include which can be used for date validation.
ajax.addParam('sysparm_name', 'getDateTimeDiff');
ajax.addParam('sysparm_fdt', startDate);
ajax.addParam('sysparm_sdt', endDate);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(checkDateDiff);
}
// callback function where deciding to go ahead or not with form submission.
function checkDateDiff(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer <= 0) {
alert("Proposed End date must be after Proposed Start date.");
g_form.setValue('proposed_end_date', '');
g_form.showFieldMsg('proposed_end_date', 'Please provide a future date', 'error');
return false;
} else {
g_form.submit(); // This has some issue as it's going in the infinite loop and if we just return true/false from here as it's asynchronous call , it's not handled by the onSubmit function
}
}
PS: hit correct/helpful....if it helps
Thanks,
Priyanka R