zemanofgod
11/23/2015 - 2:19 PM

Planned End Date Consistency Check CS / onChange / Global

Planned End Date Consistency Check CS / onChange / Global

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var end = g_form.getValue("u_planned_end_date");
var start = newValue;

var startDate = getDateFromFormat(start,g_user_date_time_format);
var endDate = getDateFromFormat(end,g_user_date_time_format);

var ga = new GlideAjax("TimezoneOffsetCalc");
ga.addParam("sysparm_name","OffsetCalc");
ga.addParam("sysparm_start",startDate);
ga.addParam("sysparm_end",endDate);
ga.getXML(ConsistencyCheck);
}

function ConsistencyCheck(response)
{
var tz = response.responseXML.getElementsByTagName("timezone");

var gr = new GlideRecord("change_request");
gr.get(g_form.getValue("change_request"));

var reqStartDate = getDateFromFormat(gr.start_date,g_user_date_time_format);
var reqEndDate = getDateFromFormat(gr.end_date,g_user_date_time_format);
var startDate = tz[0].getAttribute("startDate");
var endDate = tz[0].getAttribute("endDate");

if (startDate > endDate && startDate != 0 && endDate > 0) {
g_form.clearMessages();
alert(getMessage('alert_change_task_planned_date_conflict'));
return;
} else if (reqStartDate == 0 && reqEndDate == 0) {
return;
}

if (reqStartDate > startDate && reqStartDate != 0) {
g_form.clearMessages();
alert(getMessage('alert_change_start_planned_start_date_conflict'));
return;
}

if (reqEndDate < startDate && reqEndDate !=0) {
g_form.clearMessages();
alert(getMessage('alert_change_end_planned_start_date_conflict'));
return;
}

}