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

32 comments:

  1. 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
  2. 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
  3. Great article, you help so many people across the world.
    Just reminding you.
    Thanks.

    ReplyDelete


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

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


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

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

    ReplyDelete
  7. 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
  8. THANK YOU FOR THE INFORMATION .HI GUYS IF SEARCHING FOR CRM Solutions PLEASE VISIT US
    CMR Solutions

    ReplyDelete
  9. Amazing Post.

    Thanks for sharing this informative Article.

    wordpress customer portal

    ReplyDelete
  10. 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
  11. 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
  12. 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

  13. 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
  14. As printers are not infallible, they are made by the human; they are likely to encounter specific issues. To confront them, reach out to Dell Printer Support that is available 24/7.
    Click on this:Dell Printer Support

    ReplyDelete
  15. This is most informative and also this post most user friendly and super navigation to all posts. Thank you so much for giving this information to me.microsoft azure training in bangalore




    ReplyDelete
  16. Superb post, we enjoyed each and everything as per written in your post. Thank you for this informative article because it’s really helpful, I really like site.
    Please visit our website : Packers And Movers Mumbai

    Packers And Movers Mumbai to Bhubaneswar
    Packers And Movers Mumbai to Bhopal
    Packers And Movers Mumbai to Lucknow
    Packers And Movers Mumbai to Chandigarh
    Packers And Movers Mumbai to Patna

    ReplyDelete
  17. Canon printers are the most selling brand throughout the globe. Canon printers are recognized for its fine features and services. Most Canon printers are ink-viable, mild and faster than different printer brands. But occasionally scenario arises when you are unable to solve the technical issues. Stop waiting and reach our canon printer support team for any assistance. Our technicians will be available 24/7 to assist you.

    ReplyDelete
  18. Very Informative! CRM Software can be used to meet all your requirements and make your business run in pace. The blog was very good. Earned Quality knowledge. Thanks

    ReplyDelete
  19. Canon printer support- Canon aims to provide the best of printers to its customers, sometimes the consumers might face technical issues that are pretty difficult to deal with. Trying your hands at the printer may escalate your problem and therefore, it is most suitable to take help from a professional who has excelled in the field.

    ReplyDelete
  20. "InnovationM is the most trusted mobile app development and web development agency in London, UK

    We design and develop the best Android & iOS apps for you. We are the best website design company in the London, Luton, Birmingham, Derby, Sheffield (United Kingdom)

    Top android app developers in London
    Best Android application development company in London
    Best iOS app developers in London
    Top iOS app development company in London
    Best web development company in London
    Top website design agency in London
    Top rated web design and development company in london
    Best software development company in London
    Top 10 software development agency in London
    For more: innovationm.co.uk"

    ReplyDelete
  21. InnovationM is the most trusted mobile app development and web development agency in London, UK

    We design and develop the best Android & iOS apps for you. We are the best website design company in the London, Luton, Birmingham, Derby, Sheffield (United Kingdom)

    Top android app developers in London
    Best Android application development company in London
    Best iOS app developers in London
    Top iOS app development company in London
    Best web development company in London
    Top website design agency in London
    Top rated web design and development company in london
    Best software development company in London
    Top 10 software development agency in London
    Mobile app development and web development agency in London, Luton, Birmingham, Derby, Sheffield, UK

    mobile app development company in luton
    mobile application development company in luton
    mobile app development company in birmingham
    mobile application development company in birmingham
    mobile app development company in sheffield
    mobile application development company in sheffield
    mobile app development company in derby
    mobile application development company in derby
    mobile app development company in london
    mobile application development company in london

    Android app development company in luton
    Android application development company in luton
    Android app development company in birmingham
    Android application development company in birmingham
    Android app development company in Sheffield
    Android application development company in Sheffield
    Android app development company in derby
    Android application development company in derby
    Android app development company in London
    Android application development company in London

    iOS app development company in luton
    iOS application development company in luton

    iOS app development company in birmingham
    iOS application development company in birmingham
    iOS app development company in Sheffield
    iOS application development company in Sheffield
    iOS app development company in derby
    iOS application development company in derby
    iOS app development company in London
    iOS application development company in London

    website development company in luton
    web development company in luton
    website development company in birmingham
    web development company in birmingham
    website development company in sheffield
    web development company in sheffield
    website development company in derby
    web development company in derby
    website development company in london
    web development company in london

    web design company in luton
    website design company in luton
    web design company in birmingham
    website design company in birmingham
    web design company in sheffield
    website design company in sheffield
    web design company in derby
    website design company in derby
    web design company in London
    website design company in London

    app developers in luton
    application developers in luton
    app developers in birmingham
    application developers in birmingham
    app developers in sheffield
    application developers in sheffield
    app developers in derby
    application developers in derby
    app developers in london
    application developers in london

    custom web design in luton
    custom website design in luton
    ecommerce web design company in luton
    custom web development company in luton
    wordpress website design company in luton
    graphic design companies websites in luton
    best website design companies for small business in luton

    custom web design in birmingham
    custom website design in birmingham
    ecommerce web design company in birmingham
    custom web development company in birmingham
    wordpress website design company in birmingham
    graphic design companies websites in birmingham
    best website design companies for small business in birmingham

    custom web design in Sheffield
    custom website design in Sheffield
    ecommerce web design company in Sheffield
    custom web development company in Sheffield
    wordpress website design company in Sheffield
    graphic design companies websites in Sheffield
    best website design companies for small business in Sheffield

    For more: innovationm.co.uk

    ReplyDelete
  22. "Great blog, good information is given.It was worth reading.Thanks for posting the blog. IT Help Desk Software | Ticketing System | Apptivo Help Desk"

    ReplyDelete
  23. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
    data scientist courses

    ReplyDelete
  24. It's acceptable to check this sort of site. I figure I would such a great amount from you.
    Data Science Training in Hyderabad
    Data Science Course in Hyderabad

    ReplyDelete
  25. Really this article is truly one of the best in article history and am a collector of old "items" and sometimes read new items if i find them interesting which is one that I found quite fascinating and should be part of my collection. Very good work!
    Data Scientist Course in Gurgaon

    ReplyDelete

My Name is..