Hi Andrii,
Still no luck. Here is this code. Interestingly, the validation part works, and the appropriate message displays. However, if the check condition is met, the form will not resolve.
function ResolveCustom() {
//debugger;
//Xrm.Page.data.entity.save();
var casetitle = Xrm.Page.getAttribute("bkm_casetitle");
var customer = Xrm.Page.getAttribute("customerid");
if (casetitle == null || customer == null
|| (casetitle != null && casetitle.getValue() == null)
|| (customer != null && customer.getValue() == null)) {
if (customer == null || (customer != null && customer.getValue() == null)) {
//alert("A customer is required.");
Xrm.Page.ui.controls.get("customerid").setFocus();
return;
}
if (casetitle == null || (casetitle != null && casetitle.getValue() == null)) {
//alert("A case title is required.");
Xrm.Page.ui.controls.get("bkm_casetitle").setFocus();
return;
}
}
var isFound = testCase("Ready for Invoicing/Close", "statuscode");
if (!isFound) {
// Use the code line below only if validation is failed then abort function save event
alert("Case status must be 'Ready for Invoicing' before resolving the case.");
return;
} else {
/* else {
//debugger;
var invoicenumber = Xrm.Page.getAttribute("bkm_invoicenumber");
//alert("invoicenumber: " + (invoicenumber != null));
if (invoicenumber != null) {
var invoiceno = invoicenumber.getValue();
//alert(invoiceno + invoiceno.length + (invoiceno != null && invoiceno.length > 0));
if (invoiceno != null && invoiceno.length > 0) {
// Call Out-Of-Box Resolve
resolve();
}
else {
// Use the code line below only if validation is failed then abort function save event
//alert("Invoice Number is required when resolving before resolving the case.");
Xrm.Page.ui.controls.get("bkm_invoicenumber").setFocus();
return;
}
}
else {
// Use the code line below only if validation is failed then abort function save event
//alert("Invoice Number is required when resolving before resolving the case.");
Xrm.Page.ui.controls.get("bkm_invoicenumber").setFocus();
return;
}
}*/
resolve();
}
}
function testCase(textValue, optionSetName) {
var isFound = false;
var status = Xrm.Page.getAttribute("statuscode");
var statusCode;
if (status != null) {
statusCode = status.getValue();
}
if (statusCode != null) {
var optionSetTypeOpts = Xrm.Page.getAttribute("statuscode").getOptions();
for (var o in optionSetTypeOpts) {
if (optionSetTypeOpts[o].text == textValue) {
if (optionSetTypeOpts[o].value == statusCode) {
isFound = true;
break;
}
}
}
}
return isFound;
}