In this article, we are going to see how to restrict the customer service associate to close/resolve the case if there are Open Activities or Child Cases still open for a Case.
Here’s how you can implement this using JavaScript and form customization:
Steps to Disable the Resolve case button
- Create a Web Resource for JavaScript
- Navigate to Settings > Customizations > Customize the System.
- Create a new Web Resource for your JavaScript code.
- Write the JavaScript Code: Write JavaScript code to check for open child cases and activities when the form is loaded and enable/disable the "Resolve Case" button accordingly.
JavaScript code
function disableResolveCaseButton(executionContext) {
var formContext = executionContext.getFormContext();
var caseId = formContext.data.entity.getId();
var fetchXmlChildCases = "<fetch no-lock='true'>" +
"<entity name='incident'>" +
"<attribute name='incidentid' />" +
"<filter>" +
"<condition attribute='parentcaseid' operator='eq' value='" + caseId + "' />" +
"<condition attribute='statecode' operator='eq' value='0' />" + // 0 is the state code for Active
"</filter>" +
"</entity>" +
"</fetch>";
var fetchXmlOpenActivities = "<fetch no-lock='true'>" +
"<entity name='activitypointer'>" +
"<attribute name='activityid' />" +
"<filter>" +
"<condition attribute='regardingobjectid' operator='eq' value='" + caseId + "' />" +
"<condition attribute='statecode' operator='eq' value='0' />" + // 0 is the state code for Open
"</filter>" +
"</entity>" +
"</fetch>";
Xrm.WebApi.retrieveMultipleRecords("incident", "?fetchXml=" + encodeURIComponent(fetchXmlChildCases)).then(
function (result) {
if (result.entities.length > 0) {
formContext.ui.controls.get("resolvecasebutton").setDisabled(true);
} else {
Xrm.WebApi.retrieveMultipleRecords("activitypointer", "?fetchXml=" + encodeURIComponent(fetchXmlOpenActivities)).then(
function (result) {
if (result.entities.length > 0) {
formContext.ui.controls.get("resolvecasebutton").setDisabled(true);
} else {
formContext.ui.controls.get("resolvecasebutton").setDisabled(false);
}
},
function (error) {
console.log(error.message);
}
);
}
},
function (error) {
console.log(error.message);
}
);
}











Join the conversation! Your thoughts help the community grow.