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?

tcotton
Giga Expert

My manager has requested that a mandatory time of 48 hours be set between planned start and planned end date. If someone tries to go other it would alert that the requested end date has exceeded 48 hours.   How can I implement this change?

Change 48 hours.JPG

8 REPLIES 8

no need to script


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.


then it should be doable.



Make a business rule that is something like this:


find_real_file.png



and then on the tab "action" check the abort and message(put something here so the user understands)


saprem_d
Giga Guru

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;


}


}


});