在我的CRM实例中是核心实体' Case'。在此范围内是默认的客户查询(customerid),它指向核心'帐户' &安培; '联系'实体。还有另一个查找指向'联系人'根据customerid中的Account值进行过滤(必须使用customerid仅选择帐户值)。还有另一个指向自定义实体的查找,它使用自动编号功能。我也试图过滤此字段(new_projectref)以显示与所选帐户值关联的记录。然而,正在抛出错误说明"'联系'实体不包含Name =' customerid'。'。"。
/* Filter Lookup */
function preFilterLookup() {
try {
Xrm.Page.getControl("new_projectref").addPreSearch(function () {
addLookupFilter();
});
} catch (error) {
//window.console.log("Prefilter lookup error " + error.message);
}
}
function preFilterLookupGeneric(sourceField, destinationField) {
try {
Xrm.Page.getControl(destinationField).addPreSearch(function () {
addLookupFilterGeneric(sourceField, destinationField);
});
} catch (error) {
// window.console.log("Prefilter lookup error " + error.message);
}
}
function addLookupFilterGeneric(sourceField, destinationField) {
try {
var companyId = Xrm.Page.getAttribute(sourceField).getValue()[0].id;
var entityType = Xrm.Page.getAttribute("customerid").getValue()[0].entityType;
alert(entityType);
if (entityType == "account") {
console.log("Company = " + companyId);
if (companyId != null) {
fetchXml = "<filter type='and'><condition attribute='customerid' operator='eq' value='"
+ companyId + "' /></filter>";
Xrm.Page.getControl(destinationField).addCustomFilter(fetchXml);
}
} else if (entityType == "contact") {
return;
}
} catch (error) {
window.console.log("Error lookup filter " + error.message);
}
}
function addLookupFilter() {
try {
var companyId = Xrm.Page.getAttribute("parentaccountid").getValue()[0].id;
// window.console.log("Company = " + companyId);
if (companyId != null) {
fetchXml = "<filter type='and'><condition attribute='customerid' operator='eq' value='"
+ companyId + "' /></filter>";
Xrm.Page.getControl("new_projectref").addCustomFilter(fetchXml);
}
} catch (error) {
// window.console.log("Error lookup filter " + error.message);
}
}
先谢谢
答案 0 :(得分:0)
customerid
是Case实体上的属性名称。如果您要对帐户或联系人字段应用过滤器,则需要更新fetchXml以使用帐户实体的ID accountid
或contactid
进行联系。
"<filter type='and'><condition attribute='accountid' operator='eq' value='" + companyId + "' /></filter>";