- 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
‎08-04-2017 02:28 AM
Code which i used :
function onSubmit() {
var str_changeType = g_form.getValue('type');
var conflict = g_form.getValue('conflict_status');
var actionName = g_form.getActionName();
var startDate = g_form.getValue('start_date'); //First Date/Time field
var endDate = g_form.getValue('end_date'); //Second Date/Time field
var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.
if(actionName == 'approve_button' ){
//alert('approvr');
if(str_changeType == 'Normal'|| str_changeType == 'Expedited'){
//alert('CT');
if(conflict == 'Conflict'){
//alert('CF');
var ajax = new GlideAjax('ClientDateTimeUtils'); // This is the script include which can be used for date validation.
ajax.addParam('sysparm_name', 'getOutageDateTimeDiff');
ajax.addParam('sysparm_fdt',startDate);
ajax.addParam('sysparm_sdt',endDate);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(function(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert('anbu'+answer);
if (answer <= 0) {
alert('test.');
return;
}
});
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2017 02:43 AM
Looks Good!