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

31 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
  14. Thanks for sharing this information

    Yaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
    Best video editing services in Hyderabad,ameerpet
    Best Graphic Designing services in Hyderabad,ameerpet­
    Best Ad Making services in Hyderabad,ameerpet­

    ReplyDelete
  15. I really appreciate DR AKHIGBE,my name is LAURIE HUGHES . I will never stop testifying DR AKHIGBE , Happiness is all i see now I never thought that I will be cured from HIV virus again. DR AKHIGBE did it for me I have been suffering from a deadly disease (HIV) for the past 2 years now, I had spent a lot of money going from one place to another, from churches to churches, hospitals have been my home every day residence. Constant checks up have been my hobby not until this faithful day, I saw a testimony on how DR AKHIGBE helped someone in curing his HIV disease in internet quickly I copied his email which is drrealakhigbe@gmail.com just to give him a test I spoke to him, he asked me to do some certain things which I did, he told me that he is going to provide the herbal cure to me, which he did, then he asked me to go for medical checkup after some days, after using the herbal cure and i did, behold I was free from the deadly disease,till now no HIV in me again he only asked me to post the testimony through the whole world, faithfully am doing it now,all the testimony of DR AKHIGBE is true please BROTHER and SISTER, MOTHER and FATHER he is great, I owe him in return. if you are having a similar problem just email him on drrealakhigbe@gmail.com or you can whats App his mobile number on +2348142454860 He can also cure these diseases like HIV and AIDS HERPES,DIABETICS,CANCER, HEPATITIS A&B,CHRONIC DISEASES, ASTHMA, HEART DISEASES, EXTERNAL INFECTION, EPILEPSY, STROKE, MULTIPLE SCLEROSIS, NAUSEA,VOMITING OR DIARRHEA LUPUS,ECZEMA,BACK PAIN,JOINT PAIN. .ETC .please email drrealakhigbe@gmail.com or whats APP him ..+2348142454860 he is a real good and honest man.
    website... https:drrealakhigbe.weebly.com

    ReplyDelete
  16. Dating apps free "CrazyKrush" highlights your personality and interests with rich dating profiles that let us know what you care about most. We ask you questions on your deal breakers and passions so you can match on what matters.

    ReplyDelete
  17. This is really a very good blog and thanks for sharing it with the community!Keep Posting Many Blogs Like this.
    crm software development company in chennai

    ReplyDelete

  18. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.thanks for your information really good and very nice web design company in velachery
    web design company in chennai

    ReplyDelete
  19. Thank you for this excellently put together blog. It is very clear and helpful. If you are in a business and want to get a highly professional and effective customer relationship management solution to make a strong client base there are a number of expert services whom you can look up to get the best solutions. Choose them wisely and get the best benefits of this best business management software system with their help.

    crm systems for small businesses|Client Management Software For Small Business|Customer Relation Management Software

    ReplyDelete
  20. 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
  21. Nice information on here, I would like to share with you all my experience trying to get a loan to expand my Clothing Business here in Malaysia. It was really hard on my business going down due to my little short time illness then when I got heal I needed a fund to set it up again for me to begin so I came across Mr Benjamin a loan consultant officer at Le_Meridian Funding Service He asked me of my business project and I told him i already owned One and i just needed loan of 200,000.00 USD he gave me form to fill and I did also he asked me of my Valid ID in few days They did the transfer and my loan was granted. I really want to appreciate there effort also try to get this to anyone looking for business loan or other financial issues to Contact Le_Meridian Funding Service On Email: lfdsloans@lemeridianfds.com / lfdsloans@outlook.com He also available on WhatsApp Contact:+1-9893943740.

    ReplyDelete

  22. Hire Best Packers And Movers Mumbai for hassle-free Household Shifting, ***Office Relocation, ###Car Transporation, Loading Unloading, packing Unpacking at affordable ✔✔✔ Price Quotation. Top Rated, Safe and Secure Service Providers who can help you with 24x7 and make sure a Untroubled Relocation Services at Cheapest/Lowest Rate
    Packers And Movers Mumbai

    ReplyDelete

  23. McAfee offers an elevated level of security and has a propelled filtering highlight. The McAfee firewall verifies the clients from obscure sites. It additionally gives the clients a full report about the dangers which the antivirus had just obstructed from the framework. The retail card of McAfee will allow the clients to download, introduce and enact McAfee item to their framework by embeddings a smaller plate or setting off to its site. Ensure that you are utilizing the most recent form of McAfee antivirus on the framework.
    OFFICE.COM/SETUP
    OFFICE.COM/SETUP
    MCAFEE.COM/ACTIVATE

    ReplyDelete

My Name is..