Not to close Close change task if the panned start is in the past
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 03:42 AM - edited ‎10-04-2023 03:42 AM
Not to close Close change task if the planned start date is in the past
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 06:44 AM
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"
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 09:55 AM
I worked as suggested im able to see error message but still im able to close the change task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 09:39 AM
They should not be able to close the CTASK before the date specified in the planned start date.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 10:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 10:36 AM
Its not working