Wednesday, 10 August 2016

Modify Subgrid Ribbon Behaviour Using Form Script

Introduction

A Quick post, just want to post how to Modify Subgrid button behaviour to always “Create New child record”, instead of “Add Existing record”.

This will use the similar method like described in the previous post before, but it does not call the custom funtion, it just will “redirect” the function to your “Create new record”.

Note: This is an unsupported way, for the supported way you can do two things:

1. Make the parent lookup field name to ‘Required’
2. Modify the Ribbon of the subgrid and Hide the ‘Add Existing’ button
*For your reference – > Nice post by Gareth: https://garethtuckercrm.com/2013/11/19/fixing-the-sub-grid-user-experience-in-crm-2013/

But, those will apply to the subgrid regardless the Condition, probably for the second method, you could apply some Enable/Display Rule on the subgrid ribbon.

But, if you want to do it only for specific entity and based on Parent Form condition (can be based on parent fields or even other entity values), then there is another way to do this that I will put the code in this post.

The Code

Ok, so back to the code.

Here is the code:
//function to insist create new record form instead of Add Existing
function openNewRecordFormFromSubgridButton(subgridName, passGridControl) {
    debugger;
    try {
        //to store the original function ones
        var originalFunctionAddNewStandard = Mscrm.GridRibbonActions.addNewFromSubGridStandard;
        var originalFunctionAddExistingStandard = Mscrm.GridRibbonActions.addExistingFromSubGridStandard;
        var originalFunctionAssociated = Mscrm.GridRibbonActions.addExistingFromSubGridAssociated;

        var primaryControl = document.getElementById('crmForm');
        var parentEntityId = Xrm.Page.data.entity.getId();
        var parentEntityTypeCode = Xrm.Page.data.entity.getEntityName();

        //add existing standard subgrid
        Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
            if (gridControl.get_id() != subgridName) {
                originalFunctionAddExistingStandard(gridTypeCode, gridControl);
            }
            else {
                var primaryControl = document.getElementById('crmForm');
                originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, null, gridControl);
            }
        }
  
        //and even possible for the N:N (but this is a rare scenario)
        //add associate subgrid (N:N)
        Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
            if (gridControl.get_id() != subgridName) {
                originalFunctionAssociated(gridTypeCode, gridControl);
            }
            else {
                var primaryControl = document.getElementById('crmForm');
                originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, null, gridControl);
            }
        }
    }
    catch (e) {

    }
}

How to call:

openNewRecordFormFromSubgridButton("mysubgrid_name", true);

Result

*Previous
image
As we can see it opens lookup to look to the Existing record, it is 1:N, the record is almost possible already linked to another record, so it will make the users confused when they open this lookup.
*After
image

*And I never set any Required field to the parent lookup value, because this field is NOT always mandatory field, so it is conditional only.

Note: Use this method if you want to control the subgrid plus button based on some conditions and using the Form on Load script (easier), and it only works for the subgrid inside the form that load the function, other subgrid from another parent entity that does not have this function will not be affected, that is the advantage of using this method, to only affect subgrid of the child based on some parent entities and the function will be placed in the Parent Entity Form OnLoad and this is unsupported way.

“This is for dynamically control the subgrid behaviour through parent form onload functions based on some conditions logic, especially for 1:N relationship that usually already linked to another parent record, so that it is supposed to insist to open new Form, instead of asking the user to choose another existing record.

Hope this helps!

Thanks

19 comments:


  1. Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy.

    I will bookmark your site and check again here often. I’m quite sure :)

    Thanks
    ERP Software Dubai

    ReplyDelete
  2. Super and the maximum exciting facts. This is clearly the shape of information that I had
    Been searching out, I am already your RSS reader now and I might frequently be careful with the present day posts.
    Oracle Fusion cloud procurement Online Training

    ReplyDelete
  3. Hi, thanks for sharing your knowledge with us, it's always good to find out more about dynamics!
    Personally, as an owner of a quite big shop, I keep having lags and the system keeps going down every few weeks. I emailed the dynamics 365 support team but I haven't heard from them yet.
    Do you know what could be the reason of this happening repeatedly?

    ReplyDelete
  4. Great article, you help so many people across the world.
    Just reminding you.
    Thanks.

    ReplyDelete


  5. تقوم افضل شركة شركة نقل عفش من الرياض الى الكويت الاعتماد على توفير عدد من الخدمات الاساسية التى تساعد فى اعمال النقل من اهم ما تقوم شركة
    نقل عفش من الرياض للكويت بتوفيره الاتى
    - الاهتمام بتوفير العماله الاساسية المدربة
    - الاعتماد على افضل السيارات الخاصه باعمال النقل
    - اسعار مميزة وارخص من اسعار النقل التقليدية
    شركة نقل عفش من الرياض الى القصيم

    افضل شركة ديكور بالرياض


    ReplyDelete
  6. Robotic Process Automation (RPA) is one of the most exciting developments in Business Process Management (BPM) in recent history. Some industry experts believe it may be even more transformational than cloud computing transformational than cloud Automationminds team. (RPA)Automationminds lets you program in (RPA),
    Robotic Process Automation course

    ReplyDelete
  7. Thank you for sharing this information. I find this information is easy to understand and very useful.
    Microsoft Dynamics AX Online Training

    ReplyDelete

  8. اذا كنت تبحث عن افضل شركات نقل العفش فاننا نقدم :

    شركة نقل عفش بالدمام ارخص شركة نقل عفش بالدمام
    شركة نقل عفش بالاحساء افضل شركة نقل عفش بالاحساء
    نقل عفش داخل مكة نقل عفش بمكة
    ارخص شركة نقل عفش بمكة

    نقل عفش داخل جدة نقل عفش بجدة
    دينا نقل عفش جدة دينا نقل عفش بجدة

    ReplyDelete
  9. Thanks for such a nice blog with full information. here you can get quality managed it support services in south africa.

    ReplyDelete
  10. Your post is really awesome. Your blog is really helpful for me to develop my skills in a right way. Thanks for sharing this unique information with us.You can also check Suite/SugarCRM Product or plugin.
    Outright Store

    ReplyDelete
  11. THANK YOU FOR THE INFORMATION .HI GUYS IF SEARCHING FOR CRM Solutions PLEASE VISIT US
    CMR Solutions

    ReplyDelete
  12. Amazing Post.

    Thanks for sharing this informative Article.

    wordpress customer portal

    ReplyDelete
  13. Great blog learned many things about Crm Software from this article, very informative .CRM system is the software that you and your company need to automate the processes and activities associated with customer relationship management. For many years, the locally hosted CRM solutions have widely been used by large corporations and medium-sized businesses. Today, you have a chance to implement the CRM systems, too. Likewise, you have a possibility to choose between the locally hosted and web based CRM solutions. The only way to make the right choice is to learn more about the different types of CRM systems.
    Best Crm Software for Small Business
    crm systems for small businesses
    best business management software
    Client Management Software for Small Business
    Customer Relation Management Software
    Customer Management Software Small Business
    Dropshipping Software

    ReplyDelete

My Name is..