Thanks for the attention! I have tried all these already.
A shortened version of my WebResource code is below. The customized button is hooked up to the ribbon_ResolveCaseScript function.
var MyCompany= MyCompany || {};
MyCompany.Crm = MyCompany.Crm || {};
MyCompany.Crm.Entities = MyCompany.Crm.Entities || {};
Type.registerNamespace("Mscrm");
Mscrm.CustomActions = function () { };
Mscrm.CustomUtilities = function () { };
Mscrm.CustomUtilities.DialogConfirmStrings = function () { };
(function () {
"use strict";
MyCompany.Crm.Entities.Case = {
DAYS_TO_INITIAL_LETTER_SENT: "new_daystoinitiallettersent",
DAYS_TO_RESOLUTION: "new_daystoresolved",
DATE_CASE_OPENED: "myc_datecaseopened",
INITIAL_LETTER_SENT: "myc_actualinitialresolutiondate",
FINAL_LETTER_SENT: "myc_actualfinalresolutiondate",
RESOLVED_IN_20_BUSINESS_DAYS: "myc_resolvedin20businessdays",
TWENTY_BUSINESS_DAYS: "myc_targetresolution20businessdaysdate",
DATE_OPENED: "myc_datecaseopened",
ribbonClose: false,
STATE_CODE: "statecode",
STATE_CODE_RESOLVED: 1,
STATE_CODE_CANCELED: 2,
STATUS_CODE: "statuscode",
STATUS_CODE_CLOSED: 854980008,
STATUS_CODE_PROBLEM_RESOLVED: 5,
STATUS_CODE_NOTIFIED_DEPARTMENT: 854980009,
STATUS_CODE_NO_IMMEDIATE_ACTION_REQUIRED: 854980010,
CASE_LOGICALNAME: "incident",
RESOLVED_ON: "myc_resolvedon",
RESOLUTION_TYPE: "myc_resolutiontype",
RESOLUTION_TYPE_PROBLEM_RESOLVED: 854980000,
RESOLUTION_TYPE_NOTIFIED_DEPARTMENT: 854980001,
RESOLUTION_TYPE_NO_IMMEDIATE_ACTION_REQUIRED: 854980002,
ribbon_ResolveCaseScript: function () {
debugger;
me.ribbonClose = true;
var recordId = Xrm.Page.data.entity.getId().replace(/[{}]/g, "");
var resolutionValue = Xrm.Page.getAttribute(me.RESOLUTION_TYPE).getValue();
Xrm.Page.getAttribute(me.RESOLVED_ON).setValue(new Date());
Xrm.Page.data.entity.save();
var completedStatusUpdate = null;
if (resolutionValue === me.RESOLUTION_TYPE_PROBLEM_RESOLVED) {
completedStatusUpdate = me.changeRecordStatus(me.CASE_LOGICALNAME, recordId, me.STATE_CODE_RESOLVED, me.STATUS_CODE_PROBLEM_RESOLVED);
}
else if (resolutionValue === me.RESOLUTION_TYPE_NOTIFIED_DEPARTMENT) {
completedStatusUpdate = me.changeRecordStatus(me.CASE_LOGICALNAME, recordId, me.STATE_CODE_RESOLVED, me.STATUS_CODE_NOTIFIED_DEPARTMENT);
}
else if (resolutionValue === me.RESOLUTION_TYPE_NO_IMMEDIATE_ACTION_REQUIRED) {
completedStatusUpdate = me.changeRecordStatus(me.CASE_LOGICALNAME, recordId, me.STATE_CODE_RESOLVED, me.STATUS_CODE_NO_IMMEDIATE_ACTION_REQUIRED);
}
else {
completedStatusUpdate = me.changeRecordStatus(me.CASE_LOGICALNAME, recordId, me.STATE_CODE_RESOLVED, me.STATUS_CODE_CLOSED);
}
},
changeRecordStatus: function (EntityLogicalName, RECORD_ID, stateCode, statusCode) {
// create the SetState request
var request =
`<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="schemas.xmlsoap.org/.../">
<s:Body>
<Execute xmlns="schemas.microsoft.com/.../Services" xmlns:i="www.w3.org/.../XMLSchema-instance">
<request xmlns:a="schemas.microsoft.com/.../Contracts" xmlns:b="schemas.microsoft.com/.../Contracts" i:type="b:CloseIncidentRequest">
<a:Parameters xmlns:c="schemas.datacontract.org/.../System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<c:key>IncidentResolution</c:key>
<c:value i:type="a:Entity">
<a:Attributes>
<a:KeyValuePairOfstringanyType>
<c:key>` + EntityLogicalName + `id</c:key>
<c:value i:type="a:EntityReference">
<a:Id>` + RECORD_ID + `</a:Id>
<a:LogicalName>` + EntityLogicalName + `</a:LogicalName>
<a:Name i:nil="true" />
</c:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<c:key>subject</c:key>
<c:value xmlns:d="www.w3.org/.../XMLSchema" i:type="d:string">Closed</c:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true" />
<a:FormattedValues />
<a:Id>00000000-0000-0000-0000-000000000000</a:Id>
<a:LogicalName>incidentresolution</a:LogicalName>
<a:RelatedEntities />
</c:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<c:key>Status</c:key>
<c:value i:type="a:OptionSetValue">
<a:Value>` + statusCode + `</a:Value>
</c:value>
</a:KeyValuePairOfstringanyType>
</a:Parameters>
<a:RequestId i:nil="true" />
<a:RequestName>CloseIncident</a:RequestName>
</request>
</Execute>
</s:Body>
</s:Envelope>`;
//send set state request
return parent.$.ajax({
type: "POST",
contentType: "text/xml; charset=utf-8",
datatype: "xml",
url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web",
data: request,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
XMLHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
},
success: function (data, textStatus, XmlHttpRequest) {
Xrm.Page.data.refresh(); // refresh current crm form
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
};
var me = MyCompany.Crm.Entities.Case;
}).call(this);