if (typeof (Crm) == "undefined")
{
Crm = { __namespace: true };
}
if (typeof (Crm.contact) == "undefined")
{
Crm.contact = { __namespace: true };
}
/*
*Module ID:无
*Author:刘赞想
*Create Date:2018-12-3
*Version:
*Depiction:联系人FormEvents事件
*/
//表单的类型
var CRM_FORM_TYPE_CREATE = 1;
var CRM_FORM_TYPE_UPDATE = 2;
var CRM_FORM_TYPE_READONLY = 3;
var CRM_FORM_TYPE_DISABLED = 4;
var CRM_FORM_TYPE_QUICKCREATE = 5;
var CRM_FORM_TYPE_BULKEDIT = 6;
Crm.contact.FormEvents = {
_FormLoad: function ()
{
Xrm.Page.getControl("new_relationdescribe")
.addPreSearch(Crm.contact.FormEvents._new_relationdescribe_fetchXml);
Xrm.Page.getAttribute("parentcustomerid").addOnChange(this._parentcustomerid_OnChange);
},
_parentcustomerid_OnChange: function ()
{
Xrm.Page.getAttribute("new_relationdescribe").setValue(null);
Xrm.Page.getControl("new_relationdescribe")
.addPreSearch(Crm.contact.FormEvents._new_relationdescribe_fetchXml);
},
_new_relationdescribe_fetchXml: function ()
{
debugger;
var fetchXml = "<filter type='and'>";
var parentcustomeridObj = Xrm.Page.getAttribute("parentcustomerid");
//var orgorgcustomerObj = Xrm.Page.getAttribute("new_organizationaccountid");
if (parentcustomeridObj != "undefined" && parentcustomeridObj != null)
{
//alert("个人")
fetchXml += "<condition attribute='new_applicablecustomertype' operator='eq' value='5' /></filter>";
//var accountid = parentcustomeridObj.getValue()[0].id.replace("}", "").replace("{", "");
//var accountEntity = Crm.contact.FormEvents._GetAccountInfo(accountid);
//if (accountEntity != null)
//{
//fetchXml += "<condition attribute='new_applicablecustomertype' operator='eq' value='" + accountEntity["new_customertype"] + "' /></filter>";
//} else
//{
//fetchXml += "<condition attribute='new_applicablecustomertype' operator='eq' value='' /></filter>";
//}
} else
{
//alert("机构");
fetchXml += "<condition attribute='new_applicablecustomertype' operator='eq' value='10' /></filter>";
}
Xrm.Page.getControl("new_relationdescribe").addCustomFilter(fetchXml);
},
_GetAccountInfo: function (accountid)
{
var results;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts(" + accountid + ")?$select=new_customertype", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function ()
{
if (this.readyState === 4)
{
req.onreadystatechange = null;
if (this.status === 200)
{
results = JSON.parse(this.response);
}
else
{
alert(this.statusText);
}
}
};
req.send();
return results;
}
}
console