Friday, 13 May 2016

Filter N to N (Many to Many) Subgrid Lookup for Existing Records in CRM Without Modifying the Ribbon Action

Introduction and Post References

Basically, in this post, I just want to show how to filter the N to N lookup in the subgrid in CRM Form, without even modifying the Global Subgrid Ribbon in CRM.

image

In my previous post: http://missdynamicscrm.blogspot.sg/2015/07/filter-nn-subgrid-in-crm-2013-using.html, I have explained about a way how to filter the N to N Subgrid Lookup, but that is needed to modify the ribbon action globally and you might need to set another condition to actually skip is you need to filter only on specific entity, but your grid will be appearing in many entities, such as:

You want to filter the Contact lookup in, if you modify the subgrid ribbon, in every contact subgrid, the filter will be applied and you might need extra code of criteria to actually limit the  execution.
Good thing about that if your entity only used for single entity and you don’t need to specify is that only for subgrid or associated view, then modifying the ribbon is a better solution. however, if you want to filter only subgrid in specific entity or form, you can actually using another way.

Like you can refer to my posts:


So, in this post, basically I try to combine the ways to become one solution, to filter the N to N lookup that only applicable once the user load the form using single javascript.  This is unsupported customization, but, remember, modifying the N to N view also needs unsupported customization, so yeah, to reach the requirement we have to go further for unsupported customization eventhough strongly I also not recommend.

The Code

So, I just try to combine the code becoming:

*For CRM 2013

function modifyRibbon(subgridName) {
    try {
        //to store the original function ones
        var originalFunctionAddNewStandard = Mscrm.GridRibbonActions.addNewFromSubGridStandard;
        var originalFunctionAddExistingStandard = Mscrm.GridRibbonActions.addExistingFromSubGridStandard;
        var originalFunctionAssociated = Mscrm.GridRibbonActions.addExistingFromSubGridAssociated;
        //add new standard subgrid
        Mscrm.GridRibbonActions.addNewFromSubGridStandard = function (gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
                }
                else {
                    originalFunctionAddNewStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }

        //add existing standard subgrid
        Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
        //add associate subgrid (N:N)
        Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
    }
    catch (ex) {
        alert(ex);
    }
}

*For CRM 2015

function modifyRibbon(subgridName) {
    try {
        //to store the original function ones
         var originalFunctionAddNewStandard = Mscrm.GridCommandActions.addNewFromSubGridStandard;
         var originalFunctionAddExistingStandard = Mscrm.GridCommandActions.addExistingFromSubGridStandard;
         var originalFunctionAssociated = Mscrm.GridCommandActions.addExistingFromSubGridAssociated;
        //add new standard subgrid
        Mscrm.GridRibbonActions.addNewFromSubGridStandard = function (gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
                }
                else {
                    originalFunctionAddNewStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }

        //add existing standard subgrid
        Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
        //add associate subgrid (N:N)
        Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
    }
    catch (ex) {
        alert(ex);
    }
}

* So the filterTrainerProfile(gridTypeCode, gridControl); is your custom function to filter the view, some as you filter and create new custom view that I also have example in my previous post:
http://missdynamicscrm.blogspot.sg/2015/07/filter-nn-subgrid-in-crm-2013-using.html.

Remember, to get the GUID of the list record to show, you can always using CRM Javascript or in CRM 2013 and above you can use smarter way that is to combine with Custom Action, since Custom Action can be called through Javascript.

http://missdynamicscrm.blogspot.sg/search?q=custom+action

Hope this helps! Jiayou!

49 comments:

  1. It was really a nice article, thanks for Share this valuable information.
    If you are looking for best Oracle financials courses we provide low price of fee for online coaching





    Oracle fusion Financials Training in hyderabad

    Oracle Fusion Financials online Training in hyderabad

    ReplyDelete
  2. Thank you for sharing such a nice and interesting blog with us. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog.
    Hyperpigmentation cream
    Viral Fever Medicines

    ReplyDelete
  3. You can achieve this without needing to touch the ribbon function at all if you combine the above with the method used by Kishore (which would not work on it's own for me in CRM 2013) shown here: https://kishored4.wordpress.com/2017/06/02/filter-nn-sub-grid-in-dynamics-365-without-custom-actions/

    My working filter:
    function preparePreSearch() {
    var myViewGuid = "{D4EDF1E1-85CD-E711-811C-005056B4252F}";
    var myViewEntity = "my_entityname";
    var myViewName = "My view name";

    setTimeout(function() {
    var subGrid_ImageButton = document.getElementById("SUBGRIDNAME_addImageButton");
    subGrid_ImageButton.addEventListener("click",function() {
    setTimeout(function() {
    var inlineElement = document.getElementById("lookup_SUBGRIDNAME_i");
    var inlineBehaviour = inlineElement.InlinePresenceLookupUIBehavior;
    inlineBehaviour.AddCustomView(myViewGuid,myViewEntity,myViewName,getFetchXml(),getLayoutXml(), true);
    }, 500);
    });
    }, 1000);
    }

    ReplyDelete
  4. Thanks for sharing the content related to Microsoft Dynamic CRM Development Services. I want to appreciate this blog and share with my friend.

    ReplyDelete

  5. كل هذه الخدمات واكثر من خلال شركة نقل عفش من الرياض الى الاردن افضل الخدمات الاساسية المميزة التى تساعد فى الوصول الى افضل النتائج المثاليه بالاضافة الى ان اعمال النقل تتم منذ لحظة اتصال عملاءنا الكرام بالشركة والبدء فى اعمال النقل منذ لحظة اتفاق مع عملاءنا الكرام فاذا اراد ان تشعر بالتميز بينا وبين اى شركة اخرى تقوم باعمال النقل واراد ان تشعر بالتميز والحفاظ على الاثاث دون ان يتاثر بالتغيرات التى تطرا على المكان فاعلم ان
    شركة نقل عفش من الرياض الى دبي هى الحل الامثل فى القيام بهذه الخدمة على الفور

    https://khalejmovers.com/

    ReplyDelete
  6. Thanks GDQ. That worked, although I had to use jQuery to find the elements. E.g.
    $("#SUBGRIDNAME_addImageButton").get(0)

    I'm using on-premise version 1612 (8.2.2.112)

    ReplyDelete
  7. Thanks for sharing this blog it's amazing blog Microsoft crm dynamic.So in this post, basically I try to combine the ways to become one solution. customer-relationship-management.

    ReplyDelete
  8. Such great information and useful article
    CRM Software

    ReplyDelete
  9. Your site is amazing and your blogs are informative and knlowledgeble to my websites.This is one of the best tips in my life.I have in quite some time.Nicely written and great info.Thanks to share the more informations.

    Seo Experts
    Seo Company
    Web Designing Company
    Digital Marketing
    Web Development Company
    App Development

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

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

    ReplyDelete
  12. Thanks for sharing detailed information its very useful.
    dynamics crm development

    ReplyDelete
  13. Nice post My sincere thanks for sharing this post Please Continue to share this post.
    Microsoft Azure Online Training

    ReplyDelete
  14. Very useful information. Thanks for sharing such a great post.

    ReplyDelete
  15. I think you have a long story to share and i am glad after long time finally you cam and shared your experience.
    python course in pune
    python course in chennai
    python course in Bangalore

    ReplyDelete
  16. Great content thanks for sharing this informative blog which provided me technical information keep posting.
    Best Devops Training in pune
    Devops interview questions and answers

    ReplyDelete
  17. https://www.besanttechnologies.com/robotic-process-automation-rpa-training-in-chennai

    ReplyDelete
  18. It is better to engaged ourselves in activities we like. I liked the post. Thanks for sharing.
    online Python training
    python training in chennai

    ReplyDelete
  19. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
    Data science training in Bangalore | Data Science Training institute in Bangalore

    ReplyDelete
  20. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    rpa training in bangalore
    best rpa training in bangalore
    rpa training in pune

    ReplyDelete
  21. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.
    Data Science Training in Indira nagar
    Data Science Training in btm layout
    Data Science Training in Kalyan nagar
    Data Science training in Indira nagar
    Data Science Training in Marathahalli
    Data science training in bangalore

    ReplyDelete
  22. Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Health Care Tipss
    All Time With You
    Article Zings
    Article Zings
    Article Zings
    Article Zings
    Article Zings
    Article Zings
    Health Carinfo

    ReplyDelete
  23. Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post. It is really very helpful for us and I have gathered some important information from this blog.

    thanks for sharing

    Breast Cancer
    Popular Massage Techniques
    Should Listen To
    Cosmetic Surgery
    Hair Loss Treatment for Men
    9 Incredible Foods That Fight Cancer
    How To Boost Up Your Small Business

    ReplyDelete
  24. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Thanks For Sharing
    Types Of Obesity
    Expensive Workout Equipment
    Blood Pressure and Weight
    Successful Journey Through Recovery
    homemade laxatives
    Deal With Stress
    How Much Do You Really Owe Your Ex?
    Can Mangosteen Cure Diabetes

    ReplyDelete
  25. Easily, the article is actually the best topic on this registry related issue. I fit in with your Python classes in pune conclusions and will eagerly look forward to your next updates.

    ReplyDelete
  26. I feel very grateful that I read this. It is very helpful and very informative and I Python classes in pune really learned a lot from it.

    ReplyDelete
  27. I feel very grateful that I read this. It is very helpful and very informative and I Python classes in pune really learned a lot from it.

    ReplyDelete
  28. Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ???Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges
    Packers And Movers Bangalore

    ReplyDelete
  29. This blog is really helpful to deliver updated educational affairs over internet which is really appraisable. I found one successful example of this truth through this blog. I am going to use such information now.
    Best surge protector

    ReplyDelete
  30. Nice blog,I understood the topic very clearly,And want to study more like this.
    Data Scientist Course

    ReplyDelete

My Name is..