Hi Guys,
I am trying to hide the resolve incident button when a field is not populated on the incident form AND the customer contract type is not 7.
it almost works, but I can't figure out how to read related record information.
I used code i already had to display warnings but it does not seem to work for buttons...
Anyone can nudge me in the right direction?
function EnableIncidentButton() {
if (Xrm.Page.getAttribute("new_invoicenum").getValue()!=null) {
return true; //if Invoice num is not null enable button don't go any furthur
}
var acct = Xrm.Page.getAttribute('customerid').getValue();
if (acct[0].entityType == "account")
{
var retrieveReq = new XMLHttpRequest();
var ODataPath = "https://crm.cartierinfo.com:444/XRMServices/2011/OrganizationData.svc/AccountSet?$select=new_servicecontract&$filter=AccountId eq guid'" acct[0].id "'";
retrieveReq.open("GET", ODataPath, true);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
retrieveData(this);
};
retrieveReq.send();
}
return false;
}
function retrieveData(retrieveReq) {
if (retrieveReq.readyState == 4) {
if (retrieveReq.status == 200) {
//Parse the result and set the field value on the form
var retrieved = JSON.parse(retrieveReq.responseText).d;
// check if contract type is NOT 7
var ContType = retrieved.results[0].new_servicecontract.Value;
if (ContType != 7) {
Xrm.Page.getAttribute("new_specialnotes").setValue('TEST TO SEE IF I CAN DO THIS');
return true; //invoice num is not null
}
}
}
return false;
}