Maintenance rules are not working as expectedIssue Maintenance rules do not work as expected and fail intermittently. This happens when a maintenance rule includes a script in the advanced section that uses return inside a condition but does not return anything if the condition is not met. When the Event Management - Maintenance Calculator job runs, it throws an exception: ClassCastException: class org.mozilla.javascript.Undefined cannot be cast to class. The cause is the missing return value in the custom script. Symptoms There are multiple maintenance rulesOne of the rules has a script in the advanced sectionThe script has "return" specified in a condition and doesn't return anything if the condition is not met.When the "Event Management - Maintenance Calculator" job runs, it throws an exception. ClassCastException: class org.mozilla.javascript.Undefined cannot be cast to class Facts The maintenance calculator job expects a return value, at least an empty string. The following is mentioned in the example script when writing custom scripts: //Make sure to create a string representation of the array return JSON.stringify(result); Release All Cause The script has the "return" specified in a condition and doesn't return anything if the condition is not met. Resolution 1. Open the maintenance rule that contains the custom script in the advanced section. 2. Review the script for any return statement used inside a condition. 3. Update the script so it always returns an object, even if the condition is not met. At minimum, return an empty string. 4. Save the maintenance rule and rerun the Event Management - Maintenance Calculator job to confirm the ClassCastException no longer occurs. If the Event Management - Maintenance Calculator job still does not execute successfully after this fix, check whether maintenance rule filters are capturing too many CIs, since the em_impact_maint_ci table has a default limit of 200,000 entries. If the limit is exceeded, disable the rule capturing excess CIs, clear the em_impact_maint_ci table, and rerun the job. If the default CI in the Change Window maintenance rule does not flag CIs listed only in the affected CIs related list, a new maintenance rule may need to be created to query the task_ci table and insert those CIs into the em_impact_maint_ci table when the related change request is Approved and in an active window state. Related Links Create maintenance rules Resolve maintenance calculator job execution failures (KB0830122) Fix CI flagging under active change window (KB0864491)