locked
CRM 2011 - addCustomView to subgrid RRS feed

  • Question

  • How would one go about adding a custom view to a subgrid lookup at run time?  The lookup control has the addCustomView method but this does not appear to function for the subgrids.

    Monday, June 20, 2011 11:53 PM

Answers

All replies

  • Hi Eric, it might help if you can post some of your code. 
    Daniel Cai | http://danielcai.blogspot.com
    Tuesday, June 21, 2011 1:47 PM
  • var oScriptlet = new ActiveXObject("Scriptlet.TypeLib");
    var viewID = oScriptlet.GUID.toString().substr(0, 38);
    var viewName = "Filtered Lookup";
    var entityName = "account";
    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXml += "<entity name='account'>";
    fetchXml += "<all-attributes />";
    fetchXml += "<filter type='and'>";
    fetchXml += "<condition attribute='name' operator='like' value='test%'/>";
    fetchXml += "</filter>";
    fetchXml += "</entity>";
    fetchXml += "</fetch>";
    
    
    var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>";
    layoutXml += "<row name='result' id='accountid'>";
    layoutXml += "<cell name='name' width='300' />";
    layoutXml += "</row>";
    layoutXml += "</grid>";
    
    
    Xrm.Page.getControl(#SUBGRID_ID#).addCustomView(viewID, entityName, viewName, fetchXML, layoutXml, true);
    

    The above code will add a custom view to a lookup control to filter for accounts that have a name like 'Test'.  However, this will throw and error of 'Object doesn't support this property or method' if you try to apply it to a subgrid.  What I need to do is apply a complex dynamic fetchXml statement against a subgrid and I had hoped that it could be accomplished by adding a custom view to the grid.  Any suggestions you can offer are appreciated.

    Tuesday, June 21, 2011 11:13 PM
  • It comes as no surprise to me that the crm grid control has no support of addCustomView method. It will require some wrestling to add the filtered lookup capability for CRM 2011 grid, if it's possible at all. 
    Daniel Cai | http://danielcai.blogspot.com


    Wednesday, June 22, 2011 4:49 AM
  • I figured out how to get this done and posted a blog about it at http://mscrmking.blogspot.com/2011/06/crm-2011-how-to-filter-add-existing.html.  Please keep in mind that the code is completely unsupported by Microsoft.

    • Marked as answer by Eric.W.Cahoon Thursday, June 23, 2011 12:15 AM
    Thursday, June 23, 2011 12:15 AM
  • Looks nice. Well done, Eric...
    Daniel Cai | http://danielcai.blogspot.com
    Thursday, June 23, 2011 4:34 AM
  • Hi Eric, I have a custom entity called weeklyservicetask. In that I have a grid that displays all service activities for a given user.  I have a date field (new_week).  When I select a date, I need to filter the grid by week of that date. I can have a custom view (fetch XML). However, I must admit that I am lost in your blog. (it’s quite impressive). Appreciate if you could help me with some steps. Thanks a lot.

    Saturday, July 9, 2011 5:14 PM
  • Thank you for the complement.  Are you trying to filter the records that are displayed on the grid or are you trying to filter the list of available records when a user attempts to add new records to the grid?

    Monday, July 11, 2011 8:55 PM
  • I am trying to filter the records that are displayed in the grid.  The grid should filter based on the week of the date field and display only those service activities for the given week. As of today, the grid displays all service activities for the user. 
    Saturday, August 6, 2011 4:50 PM
  • I try to do the same: Filtering a Sub-Grid (of a new entity we created) by the accountID. I have the example in http://mscrmking.blogspot.com/2011/06/crm-2011-how-to-filter-add-existing.html implementet. But nothing changes in my Sub-Grid. Also no error occurs, so I can´t find out what can be the problem.

    I have CRM 2011 UR3.

    Is there any other documentation or trick as the link above and the SDK documentation?

    Thursday, August 25, 2011 6:31 AM
  • I stumbled upon a blog post which elegantly solves this puzzle for CRM 2011.  I'm able to manipulate it as necessary.

    http://crmgreenbible.blogspot.com/2011/07/crm-2011-change-subgrid-fetchxml.html

    • Proposed as answer by mycapi Wednesday, September 7, 2011 9:46 AM
    Tuesday, September 6, 2011 7:21 PM
  • Thanks for your Post. It solved my problem and is much easier. Only this lines an you have it:

     //Inject the new fetchXml

      leadGrid.control.setParameter("fetchXml", fetchXml);
      //Force the subgrid to refresh
      leadGrid.control.refresh();

     

    Wednesday, September 7, 2011 9:48 AM
  • I stumbled upon a blog post which elegantly solves this puzzle for CRM 2011.  I'm able to manipulate it as necessary.

    http://crmgreenbible.blogspot.com/2011/07/crm-2011-change-subgrid-fetchxml.html


    That's a really nice discovery by both you and the blogger. Thanks for sharing.
    Daniel Cai | http://danielcai.blogspot.com
    Wednesday, September 7, 2011 3:23 PM
  • I've updated my blog to include the post by James.  A few things to point out about this solution

    • This only changes the fetchXML used and does control which columns are displayed
    • This will throw an error if you exclude attrbiutes that are displayed in the view

    I have refactored my original logic and I am hoping to be able to repost the artical with the refactored code and additional explanation in the next few days.

    Wednesday, September 7, 2011 3:49 PM
  • How would one go about adding a custom view to a subgrid lookup at run time?  The lookup control has the addCustomView method but this does not appear to function for the subgrids.

    Hi Eric,do you had some answer for addCustomView to a subgrid ,no lookup?

    i  had same problem,but i looked all answer ,i had't find how to do? do you have a true answer?

    Friday, September 9, 2011 10:05 AM
  • I am having similar requirement..  The link you have provided broken.

     

    can you help me, how to add custom view to subgrid dynamically using javascript...

     

     

    thanks


    Guru Prasad
    Tuesday, December 13, 2011 9:46 AM
  • Hi

    I have opened a product enhancement @ MS Connect, for a supported way to add CustomViews for subgrid.

    Please vote for this enhancement, if you also need this feature in a supported way:

    https://connect.microsoft.com/dynamicssuggestions/feedback/details/753241/addcustomview-to-subgrid

    regards
    Matthias

    • Proposed as answer by Neo Yadav Thursday, May 30, 2013 7:00 AM
    • Unproposed as answer by Neo Yadav Thursday, May 30, 2013 7:00 AM
    Wednesday, July 11, 2012 12:47 PM