I need to have the maximum time of 48 hours between Planned Start Date and Planned End Date On a Change Request. Would I need to script this or is there an easier method?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 11:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 11:48 AM
no need to script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 11:52 AM
That's one way to do but if he want to have the result instantly on the form before submitting then we have to script
Nitin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 11:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 11:51 AM
Hello,
You need to find the difference between 2 dates and if it is greater than 48 hours, need to give an error message. GlideAjax can be used to acheive this. Please use below sample scripts
Client script: onChange script on end date field
function onChange(control, oldValue, newValue, isLoading) {
if(newValue){
var ga = new GlideAjax('SvcCatalogCheckEndDate'); //Name of the Script Include
ga.addParam('sysparm_name', 'chkCatEndDate'); //Name of the function in the script include
ga.addParam('sysparm_date',g_form.getValue('start_date')); //Parameter to pass to the script include
ga.addParam('sysparm_endDate', g_form.getValue('end_date')); //Parameter to pass to the script include
ga.getXML(SvcCatalogCheckEndDateParse);
}
}
//Function that gets the response and will return to the client. You can place your alert in this function
function SvcCatalogCheckEndDateParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true'){
return;
}
if(g_form.getValue('end_date') != '' && answer == 'false'){
alert(getMessage("Difference between start date and end date should be more than 48 hours"));
g_form.setValue('end_date', '');
}
}
script include: client callable
var SvcCatalogCheckEndDate = Class.create();
SvcCatalogCheckEndDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCatEndDate : function() {
var start = this.getParameter('sysparm_date'); //Passing the start date from the client
var end = this.getParameter('sysparm_endDate'); //Passing the end date from the client
var dif = gs.dateDiff(start, end, true); //Get the Different between dates.
if (dif <= 172800){
return false;
}
else
{
return true;
}
}
});