多选查找中的自定义视图 - CRM Online升级

时间:2014-01-23 08:27:50

标签: javascript dynamics-crm-2011 crm dynamics-crm-online dynamics-crm-2013

我们使用下面的代码在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中选择了自定义视图的多选查找,但会抛出以下错误:

  

“找不到请求的记录,或者您没有权限   观“。

单击错误窗口中的显示错误日志,显示以下错误详细信息:

  

“savedquery With Id = 00000000-0000-0000-0000-000000000000不   存在“。

在调试上面的javascript代码时,我发现错误是由以下代码行引发的:

   var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);

有人可以帮助我解决由于MSCRM 2013在线的LookupObjects JavaScript方法导致的此错误。

1 个答案:

答案 0 :(得分:0)

我认为您应该使用LookupObjectsWithCallback,因为LookupObjects没有返回值

LookupObjectsWithCallback(callbackReference,null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]););

其中

callbackReference={callback:function (lookupItems){
        //Do Something
    }
}