我们使用以下代码在 MSCRM online 2011 online 中运行良好,以便在单击关联实体子网格中的“添加现有记录”功能区按钮时在多选查找对话框页面中显示自定义视图。
function addExistingFromSubGridQuoteProducts(gridTypeCode, gridControl, shipmentID) {
var entity = Xrm.Page.data.entity.getEntityName();
var QuoteAttribute = Xrm.Page.getAttribute("new_quoteid");
if (QuoteAttribute == null) {
QuoteAttribute = Xrm.Page.getAttribute("new_quote");
}
var Quote = QuoteAttribute.getValue();
var Quoteid = "Unknown";
if (Quote != null) {
Quoteid = Quote[0].id;
}
var filter = "<filter type='and'>"
+ "<condition attribute='new_quoteshipmentid' operator='null' />"
+ "</filter>"
var fxml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
+ "<entity name='quotedetail'>"
+ "<attribute name='productid' />"
+ "<attribute name='productdescription' />"
+ "<attribute name='priceperunit' />"
+ "<attribute name='quantity' />"
+ "<attribute name='extendedamount' />"
+ "<attribute name='quotedetailid' />"
+ "<order attribute='productid' descending='false' />"
+ filter
+ "<link-entity name='quote' from='quoteid' to='quoteid' alias='aa'>"
+ "<filter type='and'>"
+ "<condition attribute='quoteid' operator='eq' value='" + Quoteid + "' />"
+ "</filter>"
+ "</link-entity>"
+ "</entity>"
+ "</fetch>";
addExistingFromSubGridCustom({
entityName: entity,
gridTypeCode: gridTypeCode,
gridControl: gridControl,
fetchXml: fxml,
layoutXml: "<grid name='resultset' " +
"object='1' " +
"jump='productid' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " + "id='quotedetailid'>" +
"<cell name='productid' width='300' />" +
"<cell name='productdescription' width='300' />" +
"</row>" +
"</grid>"
});
}
function addExistingFromSubGridCustom(params) {
viewId = "{00000000-0000-0000-0000-000000000001}";
var customView = {
fetchXml: params.fetchXml,
id: viewId,
layoutXml: params.layoutXml,
name: "Filtered Lookup View",
recordType: params.gridTypeCode,
Type: 0
};
var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
if (lookupItems && lookupItems.items.length > 0) {
for (var i = 0; i< lookupItems.items.length; i++){
var lhsEntityId;
var lhsSet;
var relatedEntityId;
var relatedEntitySet = "";
var relationName = "";
lhsEntityId = Xrm.Page.data.entity.getId();
lhsSet = "new_quoteshipmentSet";
relatedEntityId = lookupItems.items[i].id;
relatedEntitySet = "QuoteDetailSet";
relationName = "new_quoteshipment_quotedetail";
var done = XrmServiceToolkit.Rest.Associate(
lhsEntityId,
lhsSet,
relatedEntityId,
relatedEntitySet,
relationName,
function () {
var i = 0;
},
function (error) {
var i = 0;
},
false
);
}
params.gridControl.refresh();
}
}
但升级到 MSCRM 2013 后,此代码显示多选查找,并在 viewpicker 中选择了自定义视图,但引发以下错误:
“未找到请求的记录或您无权查看。”</p>
单击错误窗口中的显示错误日志,显示以下错误详细信息:
“Id = 00000000-0000-0000-0000-000000000000 的已保存查询不存在。”</p>
在调试上述javascript代码时,我发现错误是由以下代码行引发的:
var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
由于 MSCRM 2013 在线中的 LookupObjects JavaScript 方法,有人可以帮我解决这个错误。