title: Custom view in multi-selected lookup - CRM Online upgrade
body: <p>We were using below code that works fine in MSCRM online 2011 online to show custom view in multi-selected lookup dialog page on click of Add Existing Records ribbon button in subgrid of associated entity.</p>
  
  <pre class="lang-js prettyprint-override"><code>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 =  "&lt;filter type='and'&gt;"
  
                 + "&lt;condition attribute='new_quoteshipmentid' operator='null' /&gt;"
  
                 + "&lt;/filter&gt;"
  
      var fxml = "&lt;fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'&gt;"
  
       + "&lt;entity name='quotedetail'&gt;"
  
         + "&lt;attribute name='productid' /&gt;"
  
         + "&lt;attribute name='productdescription' /&gt;"
  
         + "&lt;attribute name='priceperunit' /&gt;"
  
         + "&lt;attribute name='quantity' /&gt;"
  
         + "&lt;attribute name='extendedamount' /&gt;"
  
         + "&lt;attribute name='quotedetailid' /&gt;"
  
         + "&lt;order attribute='productid' descending='false' /&gt;"
  
         + filter
  
         + "&lt;link-entity name='quote' from='quoteid' to='quoteid' alias='aa'&gt;"
  
           + "&lt;filter type='and'&gt;"
  
             + "&lt;condition attribute='quoteid' operator='eq' value='" + Quoteid + "' /&gt;"
  
           + "&lt;/filter&gt;"
  
         + "&lt;/link-entity&gt;"
  
       + "&lt;/entity&gt;"
  
     + "&lt;/fetch&gt;";
  
     addExistingFromSubGridCustom({
  
         entityName: entity,
  
         gridTypeCode: gridTypeCode,
  
         gridControl: gridControl,
  
         fetchXml: fxml,
  
         layoutXml: "&lt;grid name='resultset' " +
  
                          "object='1' " +
  
                          "jump='productid' " +
  
                          "select='1' " +
  
                          "icon='1' " +
  
                          "preview='1'&gt;" +
  
                      "&lt;row name='result' " + "id='quotedetailid'&gt;" +
  
                        "&lt;cell name='productid' width='300' /&gt;" +
  
                        "&lt;cell name='productdescription' width='300' /&gt;" +
  
                      "&lt;/row&gt;" +
  
                    "&lt;/grid&gt;"
  
     });
  
  }
  
  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 &amp;&amp; lookupItems.items.length &gt; 0) {
  
     for (var i = 0; i&lt; 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();
  
      }
  
  }
  </code></pre>
  
  <p>But after upgrade to MSCRM 2013, This code shows multi-selected lookup with custom view selected in viewpicker but throws following error:</p>
  
  <blockquote>
    <p>“The requested record was not found or you do not have permissions to
    view.”</p>
  </blockquote>
  
  <p>On click of show error logs in error window, following error detail was shown:</p>
  
  <blockquote>
    <p>“savedquery With Id = 00000000-0000-0000-0000-000000000000 Does Not
    Exist.”</p>
  </blockquote>
  
  <p>On debugging of above javascript code, I found that the error is thrown by following line of code:</p>
  
  <pre class="lang-js prettyprint-override"><code>   var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
  </code></pre>
  
  <p>Could someone please help me in fixing of this error due to LookupObjects JavaScript method in MSCRM 2013 online.</p>