我們使用以下代碼在MSCRM online 2011 online中正常工作,在多選查找對話框頁面中顯示自定義視圖,單擊關聯子網格中的添加現有記錄功能區按鈕實體。多選查詢中的自定義視圖 - CRM在線升級
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選擇自定義視圖,但會引發以下錯誤:
「The requested record was not found or you do not have permissions to view.」
在錯誤窗口中顯示錯誤日誌的點擊,以下錯誤的細節被示出:
「savedquery With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist.」
基於以上JavaScript代碼調試,我發現,誤差由以下的代碼行拋出:
var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
有人可以幫我解決這個錯誤,因爲MSCRM 2013在線的LookupObjects JavaScript方法。