CRM 2016 Related Records Filtering RRS feed

  • Question

  • Hi,

    After upgrading to CRM 2016, the lookup field's filtering stopped working. Not sure how to troubleshoot. And nothing has been changed settings wise.

    We have a couple of lookup fields on the form, all of which are dependent on another custom lookup field 'A'.

    Lookup field 'A' gets its value filled in on form load through a script based on the current user.
    And all the lookup fields needs to be filtered based on lookup field 'A'.

    We have setup 'Related Records Filtering' on all the lookup fields correctly and I am sure, as things were working fine until we upgraded.

    Can anybody please suggest some troubleshooting tips? Thanks for any help!  

    • Edited by ReignFan Monday, November 20, 2017 4:37 PM
    Monday, November 20, 2017 4:37 PM

All replies

  • BUmp.

    • Edited by ReignFan Saturday, November 25, 2017 3:02 PM
    Saturday, November 25, 2017 3:02 PM
  • Hi,

    Without knowing how you did it in the past (Did you access the dom directly?), there are examples that show how to do this.

    Does your filter need to be dynamic, as in change on the form back and forth? Or is it enough to set it when you load the form?

    I made the following code for my system and it works for me, since you have multiple filters you might have to have multiple PreSearch variables, since they need to be exact if you are switching out some filter. As I mention in the comments this only works for 1 field on each form currently, modifying it to work with more should not be much of a problem.

    Hope it helps.

    //Global variable that is needed to store the last filter that was used.
        //If preSearch filter is not stored then it cannot be removed to be replaced with another one.
        var PreSearch = null;
        //Function that handles adding a custom filter to the lookup field.
        //controlName : is the name of the lookup field to modify search on.
        //filterXml : is the filter to apply to the lookup field, send in null to clear the filter from the control.
        //filter example - "<filter type='and'><condition attribute='ATTRIBUTENAME' operator='eq' value='VALUE' /><condition....etc.../></filter>"
        //entity : is optional and is used to limit filter to a specific entity, used for customer and regarding fields, send in null to ignore
        this.AddCustomFilter = function (controlName, filterXml, entity) {
            //Check if preSearch field is null
            if (PreSearch !== null) {
                //Remove the previous presearch
            //Check if the filterxml is null.
            if (filterXml !== null) {
                //Store the last presearch used.
                PreSearch = function () {
                    if (entity !== null) {
                        //Add the custom filter generated from the filterXml and entity.   
                        Xrm.Page.getControl(controlName).addCustomFilter(filterXml, entity);
                    else {
                        //Add the custom filter generated from the filterXml without the entity.   
                //Add the preSearch to the control
            else {
                //Set the presearch object to null since no filter was applies.
                PreSearch = null;
        };// END : this.AddCustomFilter = function (controlName, filterXml)

    Best regards,

    Halldór Jóhannsson

    Wednesday, November 29, 2017 9:08 AM
  • Hi Halldor,

    I am not looking for custom filtering. We have set up out of the box lookup fields with regular settings from field properties(Related records filtering).

    No custom code/script involved in it. Everything used to work fine until we upgraded to CRM 2016. Also, filtering works fine after saving the form but not on the form load.

    The filtering field is also a lookup field and it gets its value through a script, though. I am pretty sure, the lookup field value is setting properly on the form load as other things are working fine which depend on that lookup field.

    Thank you. Please let me know if I haven't clarified properly.

    • Edited by ReignFan Wednesday, November 29, 2017 4:57 PM
    Wednesday, November 29, 2017 4:57 PM
  • Ahh, I thought you had custom filtering.

    Why the related checkbox is not working is something I do not remember having encountered, my first quess would be to check the view that is used and see if anything got either reset or bugged there, otherwise I would suggest making a ticket with Microsoft.

    Best regards,

    Halldór Jóhannsson

    Wednesday, November 29, 2017 6:17 PM