Not to close Close change task if the panned start is in the past

SamJam
Tera Contributor

Not to close Close change task if the planned start date is in the past

10 REPLIES 10

Amit Gujarathi
Giga Sage
Giga Sage

HI @SamJam ,
I trust you are doing great.
You can create onbefore BR using below configuration

    • Name: "Prevent Close if Planned Start in Past"
    • Table: "Change Task"
    • When: "Before"
    • Insert/Update: Check "Update"
    • Filter Conditions: "State changes to Closed"
  1. Advanced: Check the "Advanced" checkbox.

(function executeRule(current, previous /*null when async*/) {
    // Check if Planned Start is in the past
    var plannedStart = new GlideDateTime(current.planned_start);
    var now = new GlideDateTime();

    if (plannedStart.before(now)) {
        // Prevent the change task from being closed
        current.setAbortAction(true);
        gs.addErrorMessage("Cannot close the Change Task as the Planned Start date is in the past.");
    }
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



I worked as suggested im able to see error message but still im able to close the change task.

They should not be able to close the CTASK before the date specified in the planned start date.

Hi @SamJam,

 

Create a onSubmit Client script:

 

function onSubmit() {
var startDate = g_form.getValue("start_date");
var nowDate =  Number(new Date());
var format = g_user_date_time_format;
var state = g_form.getValue('state');
if (state == 3 || state == 4){
	
	if (startDate === "")
	return true;
	
	// get date strings into a number of milliseconds since 1970-01-01
	var startDateMs = getDateFromFormat(startDate, format);
	var nowMs = getDateFromFormat(nowDate, format);
	
	if (startDateMs < nowMs)
	return true;
	
	g_form.clearMessages();
	
	if (startDateMs > nowMs) {
		g_form.addErrorMessage(new GwtMessage().getMessage("You cannot close the task before the planned start date"));
		
		return false;
		
	}
}
else{
	return true;
}
}

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Its not working