Wednesday, June 22, 2011

CRM 2011 - How to filter the 'Add Existing' button on a sub-grid. (A.K.A. filtered sub-grid look up)

Update 07 September 2011

If you are looking for a simpler solution that only allows for changing the fetchXML used by the lookup control check out James's post at CRM 2011 Change SubGrid FetchXML.


I had hoped that Microsoft would provide support for applying custom views to the lookup used by sub-grids, since you can use the Xrm.Page.ui.addCustomView method to apply a custom view to a lookup control. Unfortunately, the Xrm.Page.ui.addCustomView method only works for lookup controls. So for the past three full days I have spent my time trying to understand how the addCustomView method works so I could extend it to support sub-grids. The code below does this; however, IT HAS BEEN TESTED MINIMALLY and thus may not address your particular case. If you find issues or improve this please let me know so I can share it with the rest of the community.

//Warning: This code below is not supported by Microsoft

//Place this code in the onload event of a form containing a sub-grid that you wish to filter

window.attachEvent("onload", function() {
  function locAssocObj_custom(iType, sSubType, sAssociationName, iRoleOrdinal, additionalParams, showNew, showProp, defaultViewId, customViews, allowFilterOff, disableQuickFind, disableViewPicker, viewsIds) {
    var lookupItems = LookupObjects(null, "multi", iType, 0, null, additionalParams, showNew, showProp, null, null, null, null, defaultViewId, customViews, null, null, null, null, allowFilterOff, disableQuickFind, disableViewPicker, viewsIds, false);
    if (lookupItems) lookupItems.items.length > 0 && AssociateObjects(crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, iType, lookupItems, iRoleOrdinal == 2, sSubType, sAssociationName)
  }

  if (Mscrm.GridRibbonActions.addExistingFromSubGridAssociated) {
    Mscrm.GridRibbonActions.addExistingFromSubGridAssociated_org = window.Mscrm.GridRibbonActions.addExistingFromSubGridAssociated;

    window.Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function(gridTypeCode, gridControl) {
      if (IsNull(gridControl)) {
        throw Error.argument("value", "gridControl is null or undefined")
        return;
      }

   //Check if a filtered grid.  If not call default method      
      if (IsNull(gridControl._element.isFiltered) || !gridControl._element.isFiltered) {
        Mscrm.GridRibbonActions.addExistingFromSubGridAssociated_org(gridTypeCode, gridControl)
      } else {
        var e = document.getElementById(gridControl._element.id);

        var showNew = (IsNull(e.showNew) ? null : e.showNew);
        var showProp = (IsNull(e.showProp) ? null : e.showProp);
        var allowFilterOff = (IsNull(e.allowFilterOff) ? null : e.allowFilterOff);
        var disableQuickFind = (IsNull(e.disableQuickFind) ? null : e.disableQuickFind);
        var disableViewPicker = (IsNull(e.disableViewPicker) ? null : e.disableViewPicker);
        var customViews = (IsNull(e.customViews) ? null : e.customViews);
        var defaultViewId = (IsNull(e.defaultViewId) ? null : e.defaultViewId);
        var viewsIds = null;

        var $v_0 = gridControl.getParameter("relName"), $v_1 = gridControl.getParameter("roleOrd"), $v_2 = false;

        switch (gridTypeCode) {
          case Mscrm.EntityTypeCode.List:
            switch ($v_0) {
              case "campaignactivitylist_association":
                window.parent.locAssocObjCampaignActivity(gridTypeCode, "", $v_0, $v_1);
                break;
              case "campaignlist_association":
                locAssocObjCampaign(gridTypeCode, "subType=targetLists", $v_0, $v_1);
                break;
              case "listlead_association":
                window.parent.locAssocObjLead(gridTypeCode, "", $v_0, $v_1);
                break;
              case "listcontact_association":
                window.parent.locAssocObjContact(gridTypeCode, "", $v_0, $v_1);
                break;
              case "listaccount_association":
                window.parent.locAssocObjAccount(gridTypeCode, "", $v_0, $v_1);
                break;
              default:
                $v_2 = true;
                break
            }
            break;
          case Mscrm.EntityTypeCode.Campaign:
            switch ($v_0) {
              case "campaignlist_association":
                locAssocObjList(gridTypeCode, "subType=targetLists", $v_0, $v_1);
                break;
              case "campaigncampaign_association":
                locAssocObjCampaign(gridTypeCode, "", $v_0, $v_1);
                break;
              default:
                $v_2 = true;
                break
            }
            break;
          case Mscrm.EntityTypeCode.Product:
            switch ($v_0) {
              case "productsubstitute_association":
                locAssocObjProduct(gridTypeCode, "", $v_0, $v_1);
                break;
              case "productassociation_association":
                locAssocObjProduct(gridTypeCode, "", $v_0, $v_1);
                break;
              case "campaignproduct_association":
                locAssocObjCampaign(gridTypeCode, "", $v_0, $v_1);
                break;
              case "competitorproduct_association":
                window.parent.locAssocObjCompetitor(gridTypeCode, "", $v_0, $v_1);
                break;
              default:
                $v_2 = true; break
            }
            break;
          default:
            $v_2 = true;
            break
        }
        if ($v_2) {
          var $v_3 = locAssocObj_custom;
          var additionalParams = null;
          //$v_3(gridTypeCode,"",$v_0,$v_1, additionalParams)     
          $v_3(gridTypeCode, "", $v_0, $v_1, additionalParams, showNew, showProp, defaultViewId, customViews, allowFilterOff, disableQuickFind, disableViewPicker, viewsIds);
        }
      }
    }
  }
});

function addSubgridCustomView(subgridID, entityTypeCode, displayName, fetchXML, layoutXML, filterType, isDefault) {
/// <summary>
/// Adds a custom view to lookup page used by a subgrid
/// </summary>
/// <param name="subgridID" type="string">
/// ID of sub-grid to add custom view to
/// </param>
/// <param name="entityTypeCode" type="int">
/// The entity type code returned by the fetch statement
/// </param>
/// <param name="displayName" type="string">
/// The name to use for the view
/// </param>
/// <param name="fetchXML" type="string">
/// The fetch XML to be used by the view
/// </param>
/// <param name="layoutXML" type="string">
/// The layout XML to be used by the view.
/// If layoutXML == null the layout from the default view of the entity will be used
/// </param>
/// <param name="filterType" type="int">
/// Type of custom view.  Default is 0
/// </param>
/// <param name="isDefault" type="boolean">
/// The layout XML to be used by the view.  
/// If layoutXML == null the layout from the default view of the entity will be used
/// </param>
/// <returns type="nothing" />
 if (IsNull(subgridID)) { throw Error.argument("value", "ID of sub-grid to filter not provided") ; return; }
 if (IsNull(entityTypeCode)) { throw Error.argument("value", "Entype code of returned object by fetchXML not provided"); return; }
 if (IsNull(fetchXML)) { throw Error.argument("value", "FetchXml not provide for custom view on sub-grid"); return; }
 if (IsNull(layoutXML)) { throw Error.argument("value", "LayoutXml not provided for custom view on sub-grid"); return; }

 var grd = document.getElementById(subgridID);

 //Check if the sub-grid has any customViews already.
 var customViews = (IsNull(grd.customViews) ? new Array() : grd.customViews);

 var oScriptlet = new ActiveXObject("Scriptlet.TypeLib");
 var viewId = oScriptlet.GUID.toString().substr(0, 38);  //Call substr to address issue of trailing white space
 
 //Create an object to hold the customView's information
 var customView = new Object();
   customView.fetchXml = fetchXML;
   customView.id = viewId;
   customView.layoutXml = layoutXML;
   customView.name = (IsNull(displayName) || displayName == "" ? "Filtered Lookup" : displayName);
   customView.recordType = entityTypeCode;
   customView.Type = (!IsNull(filterType) ? filterType : 0);

 //Add the customView object to the array of customViews
 customViews.push(customView);      

 //Add the array of custom views to the sub-grid
 grd.customViews = customViews;

 //Set this view as the default if desired
 if (isDefault) { grd.defaultViewId = viewId; }
}

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>";

//Build the layout to use in the lookup.  Keep in mind that you will need to know the Object Type Code
//and the primary key of object displayed
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>";
   
//Apply custom view / lookup filter to the grid
addSubgridCustomView("#GRID_ID#", #OBJECT_TYPE_CODE#, "Test", fetchXML, layoutXML, 0, true);

27 comments:

  1. Hi, I hope I understand your purpose of this post in right way. I need to prepare custom view for subgrid lookup which would filter records of my custom entity(services) according to a field on a form (records of selected client on invoice form). I would like to use your code but it's very difficult and i don't understand it at all. Please say sth about your project to make it easier to analyze and configure for our custom needs. Which part of your code define the name of the subgrid? What entity you are working on and what entity records your are filtering (on what parameters)? Please, I need your help. Regards. Monika

    ReplyDelete
  2. Mona,

    Please provide the name of the entity you are filtering, the filtered entities object type code, and the name of the grid and I should be able to show you how to use the above code to filter the sub-grid lookup form.

    ReplyDelete
  3. So…I prepared custom entity called „invoiced services ” and I have relationship 1:N between “invoice” and this custom entity ("invoiced services" are my equivalent of "invoiced products" which we can add to invoice, but they become from executed and finished services from serviceappointment entity). I need to be able to add one or many “invoiced services” to invoice but my aim is to give my users ability to choose only from those records which have the same name (customerid) of the client as the name (customerid) chosen on invoice form.

    First I wanted to have this relationship visible on navigation panel on invoice form but I can put the subgrid on general form if it is really/only possibility to filter records to select.

    So I want to filter “invoiced services” entity, subgrid name is “invoicedservices”, the name of the field on invoice form on what I want to filter is “customerid”, the name of the field on “invoiced services” is “kan_client”, the primary key name of “invoiced services” is “kan_invoicedservicesid”.

    I checked object type code of “invoice services” entity by your code (var etc = Xrm.Page.context.getQueryStringParameters().etc) using it onLoad of “invoice services” form. It has given me number “10009”, but I’m not sure you were really asking me about it.

    I hope thet this is enough clear. If you need more informations please give me to know. I would be very, very, very grateful for your help.

    (By the way I have seen Jim’s Wang blog and his solution for multilookup filtering but it’s for version 4.0 and not for online crm which I’m using (I think his solution with plugin and javascript is far more difficult than yours - if obviously they really do what i need). I hope your solution will help in my case). Regards, Mona.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hi, I'm trying to use your code to filter a subgrid which represents a many-to-many relationship between two custom entities. The Custom View "Test" is succesfully created but the filtering (my own fetchxml) is not applied. Do you have any idea what could go wrong?

    FYI : I've also replaced the condition on line 21 with "if (1==2)" otherwise the code in the else statement would never be executed.

    ReplyDelete
  6. Mona,

    Based on the information you provided I believe the code below will get you the results you seek. You may need to adjust some items such as to and from attributes in the link-entity line of the fetchXML variable.

    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXML += "<entity name='kan_invoicedservices'>";
    fetchXML += "<all-attributes />";
    fetchXML += "<link-entity name='invoice' from='kan_invoiceid' to='invoiceid'>";
    fetchXML += "<filter type='and'>";
    fetchXML += "<condition attribute='customerid' operator='eq' value='" + Xrm.Page.getAttribute("customerid").getValue()[0].id + "' />";
    fetchXML += "</filter>";
    fetchXML += "</link-entity>";
    fetchXML += "</entity>";
    fetchXML += "</fetch>";

    //Build the layout to use in the lookup. Keep in mind that you will need to know the Object Type Code
    //and the primary key of object displayed
    var layoutXML = "<grid name='resultset' object='10009' jump='name' select='1' icon='1' preview='1'>";
    layoutXML += "<row name='result' id='kan_invoicedservicesid'>";
    layoutXML += "<cell name='rga_name' width='300'>";
    layoutXML += "</cell>";
    layoutXML += "</row>";
    layoutXML += "</grid>";

    //Apply custom view / lookup filter to the grid
    addSubgridCustomView("invoicedservices", 10009, "Filtered Invoiced Services", fetchXML, layoutXML, 0, true);

    ReplyDelete
  7. Hi Stig,

    Please post the fetchXML, with the names of the entities in the relationship, and the name of the N:N relationship between the entities. All so, have you tried using Fiddler2, http://www.fiddler2.com/fiddler2/, to see the fetchXML that is being sent to the server when the lookup form displays or you refresh the grid on the lookup form?

    ReplyDelete
  8. Eric, thank you for this, but I'm still uncertain how can I use all the rest of your code. I guess I should use addSubgridCustomView function with my custom parameters (fetch and layout you gave me) onLoad of my invoice form(?). What about the rest - window.attachEvent("onload", function() { .... which you adviced to place in the onload event of a form containing a sub-grid. I don't understand what is this code for :(. Should I change sth there? Should I change sth in addSubgridCustomView definition? Now, After first test of using your code I get an error : Field:window, event:onLoad, error: cannot get property "paramName": object is empty or undefinied. Please give me more tips how use this code. Is it ok to place var fetchXML and var layoutXML in my javascript file where i call addSubgridCustomView("invoicedservices", 10009, "Filtered Invoiced Services", fetchXML, layoutXML, 0, true)? Regards, Mona.

    ReplyDelete
  9. Hi Eric,

    This is the XML I'm using:

    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXML += "<entity name='em_eventcategory'>";
    fetchXML += "<all-attributes>";
    fetchXML += "<filter type='and'>";
    fetchXML += "<condition attribute='name' operator='eq' value='testing'>";
    fetchXML += "</condition></filter>";
    fetchXML += "</all-attributes></entity>";
    fetchXML += "</fetch>";

    //Build the layout to use in the lookup. Keep in mind that you will need to know the Object Type Code
    //and the primary key of object displayed
    var layoutXML = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>";
    layoutXML += "<row name='result' id='em_eventcategoryid'>";
    layoutXML += "<cell name='em_name' width='300'>";
    layoutXML += "</cell></row>";
    layoutXML += "</grid>";

    I've been using Fiddler2 to inspect what is being sent to the server, and the SOAP Envelope does contain the word 'testing' (the filter I've specified in the FetchXML).

    ReplyDelete
  10. Eric, I've misspelled the fetchxml, this is the correct version I'm using.

    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXML += "<entity name='em_eventcategory'>";
    fetchXML += "<all-attributes>";
    fetchXML += "<filter type='and'>";
    fetchXML += "<condition attribute='em_name' operator='eq' value='testing'>";
    fetchXML += "</condition></filter>";
    fetchXML += "</all-attributes></entity>";
    fetchXML += "</fetch>";

    //Build the layout to use in the lookup. Keep in mind that you will need to know the Object Type Code
    //and the primary key of object displayed
    var layoutXML = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>";
    layoutXML += "<row name='result' id='em_eventcategoryid'>";
    layoutXML += "<cell name='em_name' width='300'>";
    layoutXML += "</cell></row>";
    layoutXML += "</grid>";

    ReplyDelete
  11. Hi Eric, I'm getting "cannot create object" on line 128. I'm using your example code for xml.
    The following code is called onload:
    prepareSubform();

    addSubgridCustomView("M_ModulesPlanned", 1, "Test", fetchXML, layoutXML, 0, true);

    prepareSubform() contains all your code that must be called on load of the mainform.

    Do you know what's going wrong?

    ReplyDelete
  12. Stig,

    The <all-attributes> node in the fetchXML variable should not wrap the filter node. Additionally, you need to set the object attribute of the layoutXML to be the object type code of the entity returned by the fetch statement. I have included a function, getObjectTypeCode, that takes an entity name as a parameter and then uses Microsoft logic to return the object type code of the passed in entity name.

    var getObjectTypeCode = function(entityName) {
    /// <summary>
    /// Gets the EntityTypeCode / ObjectTypeCode of a entity
    /// </summary>
    /// <param name="entityName" type="string">
    /// Name of entity to return object type code of
    /// </param>
    /// <returns type="int" />
    var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
    lookupService.SetParameter("entityName", entityName);
    var result = lookupService.Execute();

    if (result.Success && typeof result.ReturnValue == "number") {
    return result.ReturnValue;
    } else {
    return null;
    }
    }

    //Use Microsoft's code to get the object type code of the custom entity
    var eventcategoryOTC = getObjectTypeCode('em_eventcategory');

    //Build the fetchXML statement to use by the custom view
    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXML += "<entity name='em_eventcategory'>";
    fetchXML += "<all-attributes />";
    fetchXML += "<filter type='and'>";
    fetchXML += "<condition attribute='em_name' operator='eq' value='testing'>";
    fetchXML += "</condition>";
    fetchXML += "</filter>";
    fetchXML += "</entity>";
    fetchXML += "</fetch>";

    var layoutXML = "<grid name='resultset' object='" + eventcategoryOTC + "' jump='name' select='1' icon='1' preview='1'>";
    layoutXML += "<row name='result' id='em_eventcategoryid'>";
    layoutXML += "<cell name='em_name' width='300'>";
    layoutXML += "</cell>";
    layoutXML += "</row>";
    layoutXML += "</grid>";

    ReplyDelete
  13. Mona,

    Copy and paste all of the code for from line 5 - 164, this would be everything for window.onload and the addSubgridCustomView functions, into the onload event of your invoice form. Then also add something like the code below to the onload of the invoice form. Please let me know if this works out for you.

    function buildCustomView() {
    //If customerid field has a value and the form is an add or edit form add a custom view
    if (!IsNull(Xrm.Page.getAttribute("").getValue()) && (Xrm.Page.ui.getFormType == 1 || Xrm.Page.ui.getFormType == 2)) {
    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXML += "<entity name='kan_invoicedservices'>";
    fetchXML += "<all-attributes />";
    fetchXML += "<link-entity name='invoice' from='kan_invoiceid' to='invoiceid'>";
    fetchXML += "<filter type='and'>";
    fetchXML += "<condition attribute='customerid' operator='eq' value='" + Xrm.Page.getAttribute("customerid").getValue()[0].id + "' />";
    fetchXML += "</filter>";
    fetchXML += "</link-entity>";
    fetchXML += "</entity>";
    fetchXML += "</fetch>";

    //Build the layout to use in the lookup. Keep in mind that you will need to know the Object Type Code
    //and the primary key of object displayed
    var layoutXML = "<grid name='resultset' object='10009' jump='name' select='1' icon='1' preview='1'>";
    layoutXML += "<row name='result' id='kan_invoicedservicesid'>";
    layoutXML += "<cell name='rga_name' width='300'>";
    layoutXML += "</cell>";
    layoutXML += "</row>";
    layoutXML += "</grid>";

    //Apply custom view / lookup filter to the grid
    addSubgridCustomView("invoicedservices", 10009, "Filtered Invoiced Services", fetchXML, layoutXML, 0, true);
    }
    }

    function init() {
    //Add on change event to customerid to change the custom view to match the new customer
    Xrm.Page.getAttribute("").addOnChange(function() {
    addSubgridCustomView("invoicedservices", 10009, "Filtered Invoiced Services", fetchXML, layoutXML, 0, true)
    });
    //fire onchange event to force custom view to be built
    Xrm.Page.getAttribute("").fireOnChange();
    }

    init();

    ReplyDelete
  14. Thomas,

    The code for from line 5 - 164, this would be everything for window.onload and the addSubgridCustomView functions, should be outside the prepareSubform function. Give that a shot and let me know how it works out.

    ReplyDelete
  15. Eric, maybe i was not clear. I have a function containing line 5 - 105 named 'prepareSubform'.

    I have also the second function 'addSubgridCustomView' with code 106-165.

    And of course i have the variables declared.

    On the onload event of the form. I'm calling 'preparesubform' when that function is finished i call the function addSubgridCustomView.

    So my addSubgridCustomView is outside the prepareSubform function but i still get the error that the object can not be created when trying:
    var oScriptlet = new ActiveXObject("Scriptlet.TypeLib");

    Thanks for any help. This code looks great, now i just want to have it work for me to.

    ReplyDelete
  16. Eric, I've done everything you've written but with some customisations because I have got some web errors (e.g. about lack of fetchXML, addSubgridCustomView function definition and some others).

    I've put all of the code from 5 line to 164 into one function start() which I call onLoad of my invoice form. The rest code you have prepared for me I've also put together into one function make() which also I call onLoad. But I don't know where and how I should call function buildCustomView(). I have tried to use it ("buildCustomView();") before call out "init();". Is this ok? One problem was fact that In your definition of init function I don't have fetchXML and layoutXML - so I have copied them to init() from buildCustomView(). Next I've got error that there not exists definition of addSubgridCustomView() function, so I also copied it to make() function from start() (so do I really need that code in start() function?).

    Now I get only one error (I'm not sure how it looks in english version becuse I use other language) saying sth like: "There has occured error connected with nonstandard (custom) event of this field; Field:window; Event:onload; Error: Server of automatization can't create an object."

    Ehhh :( I know you have done a lot for me for now but I need more your help. Have you any idea what the problem could be? Maybe my usage of your code is still wrong? Please, help me to find out...I was so happy that solution is so near...Regards, Mona.

    ReplyDelete
  17. Thomas,

    Line 5 - 105 need to NOT be enclosed in a method. They should be placed before you define any methods or variables. In regards to lines 144 and 145, these are used to generate a GUID for the custom view. If you are having trouble using the ActiveX control try looking into using something like the Math.uuid.js library from http://www.broofa.com/2008/09/javascript-uuid-function/ which can provide you with a RFC 4122-compliant UUID. You would need to include Math.uuid.js on the desired form and then you would remove line 144 and replace line 145 with something like

    var viewId = Math.uuid();

    If that does not work please post your entire script for the form and I'll take a look and see what I can do to get this to work for you.

    ReplyDelete
  18. Mona,

    Please post all the script for the page and I'll help you work through getting it working.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. I change sth in code above. Finally it looks like this:

    function start()
    {
    code from 5 to 105
    }

    function addSubgridCustomView(subgridID, entityTypeCode, displayName, fetchXML, layoutXML, filterType, isDefault) {
    code from 107 to 164
    }

    function make()
    {
    var fetchXML = ...

    var layoutXML = ...

    addSubgridCustomView("uslugifakturowane", 10009, "Filtered Invoiced Services", fetchXML, layoutXML, 0, true);

    function init() {
    Xrm.Page.getAttribute("customerid").addOnChange(function () {
    addSubgridCustomView("uslugifakturowane", 10009, "Filtered Invoiced Services", fetchXML, layoutXML, 0, true)});

    Xrm.Page.getAttribute("customerid").fireOnChange();
    }

    init();

    }

    (I have all code above in one javascript file but I call out onLoad invoice form start() function at first and make() function next. Now I'm getting one error: Automation server can't create object. I have found your post about "'Automation server can't create object' JavaScript Error" and set changes in my internet explorer security settings but it doesn't change anything. :/ Have you any other ideas?

    ReplyDelete
  22. Ok I resolved problem with this error: Automation server can't create object. You had right. I changed 'Initialize and script ActiveX controls not marked as safe for scripting' to enable but not for my Local Intranet Zone but for Trusted webs where I firstly added my crm firm address. It works...but now nothing happens when I open invoice form...If I choose 'Add existing records' I don't see my custom view:/ Ohhhh..why it is so complicated...sorry that I produce so much comments;)...I'm still testing and waiting for your any ideas. Regards, Mona.

    ReplyDelete
  23. Ok, I think now I understand what should be where. I checked also that addSubgridCustomView() function is call out (I added an alert). My only problem is fact that custom view isn't created:/ Could mistakes in layoutXML or fetchXML be the problem? I checked them a lot of times and I think they are ok but maybe I don't really understand their definitions(?). What could be the reason? I don't get any errors from the web...Please help.Mona

    ReplyDelete
  24. Eric...all day long I analyzed my code. I don't get this. For another entity I tried to use all your code from 1 to 184 to check if it works for accounts as you present. Firstly I've got error about usage of customViews attribute (object is empty or undefinied)...but even I haven't changed anything the error stopped to appear and everything looks fine but my custom view still doesn't exist. I know that you have written that your code was minimally tested...but are you sure it works for you? Where are the differents between ours code? Maybe some subgrid settings are the reason? What subgrid id are you using? What default view have you chosen in those settings? I know it's a little stupid if it was really the problem but I don't have any other ideas. I didn't change anything in code from 1 to 105 because it is too strange and complicated for me..but maybe the problem is there? Regards, Mona.

    ReplyDelete
  25. Hi Mona,

    I am sorry that you are having so much trouble. The last thing that I can think of is setting a few additional parameters on the sub-grid. Try adding the following

    document.getElementById("uslugifakturowane").isFiltered = true;
    document.getElementById("uslugifakturowane").allowFilterOff = 1;

    in the init method before calling addSubgridCustomView. If that does not work, please send me the javascript files you are using on the page and I'll see what else might be causing this not function. I can be reached at mscrmking@gmail.com

    ReplyDelete
  26. Hi Eric,

    The above seams to be not working. Subgrid is not getting filtered.

    Sud

    ReplyDelete
  27. Eric - Can you help to implement this? I respect your time and knowledge and willing to compensate your time. Please contact me at 585-739-7165 or bmittal@netsmartz.com

    ReplyDelete