Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

get this error when hiding activities tab in social pane

Posted on by 2,397

i, I am trying to hide activities tab in social pane in dynamics 365. Below is the JS code, but  I keep getting the code when form loads. I believe the event handler is correctly set. Please advise 

700864.Capture.PNG

0702.Capture.PNG

function HideSocialPaneItems() {
    var tabs = ["ACTIVITIES"];
    for (var tabsid = 0; tabsid < tabs.length; tabsid++) {
        HideTabs(tabs[tabsid]);
    }
}

function HideTabs(socialPaneType) {
    var ctrlElement = document.getElementById("header_notescontrol");
    if (ctrlElement.children != null && ctrlElement.children.length > 0) {
        for (var ele = 0; ele < ctrlElement.children.length; ele++) {
            var ctrl = ctrlElement.children[ele];
            if (ctrl.title == socialPaneType) {
                ctrl.style.display = "none";
                if (ele + 1 < ctrlElement.children.length) { ctrlElement.children[ele + 1].click(); return; } else if (ele - 1 >= 0) {
                    ctrlElement.children[ele - 1].click();
                    return;
                }
            }
        }
    }
}

*This post is locked for comments

  • bcherisme Profile Picture
    bcherisme 54 on at
    RE: get this error when hiding activities tab in social pane

    @sdnd2000 

    Hello, I'm trying to accomplish the same thing

    Can you please share the solution to hide activities and post for an entity

    Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: get this error when hiding activities tab in social pane

    I will not pretend to understand exactly what you are doing but I see a similar error when I try to refresh the annotations list using remarkably similar code :(

    However, for hiding tabs, can't you more simply use something like this:  Xrm.Page.ui.tabs.get("tab_TOD").setVisible(false);

    Why are you trying to click on the child elements?  Also, have you tried enabling CRM365's "Legacy Form rendering" - seems to me that should be unnecessary but it was deemed necessary on a related thread:

    community.dynamics.com/.../229475

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: get this error when hiding activities tab in social pane

    I got it to work by modifying Alex Shlega's script. It didn't work with  ", I had to use '

    Here's my JS:

    function HideSocialPaneItems() {
        var tabs = ["NOTES"];
        for (var tabsid = 0; tabsid < tabs.length; tabsid++) {
            HideTabs(tabs[tabsid]);
        }
    }
    
    function HideTabs(socialPaneType) {
        var ctrlElement = document.getElementById('header_notescontrol');
        if(ctrlElement == null) ctrlElement = window.parent.document.getElementById('header_notescontrol');
        if(ctrlElement == null) return;
        if (ctrlElement.children != null && ctrlElement.children.length > 0) {
            for (var ele = 0; ele < ctrlElement.children.length; ele++) {
                var ctrl = ctrlElement.children[ele];
                if (ctrl.title == socialPaneType) {
                    ctrl.style.display = "none";
                    if (ele + 1 < ctrlElement.children.length) { ctrlElement.children[ele + 1].click(); return; } else if (ele - 1 >= 0) {
                        ctrlElement.children[ele - 1].click();
                        return;
                    }
                }
            }
        }
    }


  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: get this error when hiding activities tab in social pane
    This should work for either form type (legacy or not):


    function HideSocialPaneItems() {
        var tabs = ["ACTIVITIES"];
        for (var tabsid = 0; tabsid < tabs.length; tabsid++) {
            HideTabs(tabs[tabsid]);
        }
    }
    
    function HideTabs(socialPaneType) {
        var ctrlElement = document.getElementById("header_notescontrol");
        if(ctrlElement == null) ctrlElement = window.parent.document.getElementById("header_notescontrol");
        if(ctrlElement == null) return;
        if (ctrlElement.children != null && ctrlElement.children.length > 0) {
            for (var ele = 0; ele < ctrlElement.children.length; ele++) {
                var ctrl = ctrlElement.children[ele];
                if (ctrl.title == socialPaneType) {
                    ctrl.style.display = "none";
                    if (ele + 1 < ctrlElement.children.length) { ctrlElement.children[ele + 1].click(); return; } else if (ele - 1 >= 0) {
                        ctrlElement.children[ele - 1].click();
                        return;
                    }
                }
            }
        }
    }

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: get this error when hiding activities tab in social pane

    Like I said, getElementById always returns null for non-legacy forms. What exactly Microsoft has done there to make it work this way - no idea.. I'd actually love to understand that myself:)

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: get this error when hiding activities tab in social pane

    Here is the part that applies to the legacy forms:

    "and then you need to make one change under Administration -> System Settings -> General."

    It works, I just tried.. what happens in the next version is known to Microsoft only:)

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: get this error when hiding activities tab in social pane

    it worked, any reason for this?

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: get this error when hiding activities tab in social pane

    Yes, that's exactly what I meant and that's exactly what that link is about.

    document.getElementById("header_notescontrol");

    This returns null

    Therefore, a call to ctrlElement.children fails with that error you have on the screenshot.

    Try legacy forms and see if that helps

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: get this error when hiding activities tab in social pane

    Sorry, I put wrong image, now I updated the image, it shows "Cannot read property 'children' of null" , that is not compatibility issue, right?

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: get this error when hiding activities tab in social pane

    Hi sdnd,

     as Andrii mentioned before, this is all unsupported.. You can have a look at this thread:

    community.dynamics.com/.../229475

     I did not try, but, funny enough.. it seems that we can't use getElementById with new form rendering - legacy form rendering may help, but that will probably affect other things(performance etc) and might end up being completely unsupported in the future.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans