web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

document.getElementById always returns “null” for ribbons

(0) ShareShare
ReportReport
Posted on by

I need to set the background color of one of the buttons in the form's ribbon. This isn't supported through Ribbon Workbench, so I have written following javascripts to achieve the same:

function setOpportunityRibbonsAppearance() {
    var submitToForeCastButton = parent.document.getElementById("opportunity|NoRelationship|Form|sfw.opportunity.Button1.Button");

    if (submitToForeCastButton != null) {
        submitToForeCastButton.style.backgroundColor = "lightyellow";
    }
}

I have registered this scripts in Form Load event. However the issue is that, I always get parent.document.getElementById as null only. Surprisingly, I am able to see the control while running the parent.document.getElementById statement in the browser's console, and can also change the styling attributes.

Can anyone please suggest what could be wrong here?

P.S. - I understand document.getElementById is not recommended to use in CRM, however, I am left with no other choice while trying to change the appearance of some of the buttons.

Any help on this, will be much appreciated.

*This post is locked for comments

I have the same question (0)
  • ScottDurow Profile Picture
    21 on at
    RE: document.getElementById always returns “null” for ribbons

    Hi - this simply is something that you should never do! Not only is it unsupported it will break with future updates. You should change the images to contain the colours and show/hide different buttons with different colors.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: document.getElementById always returns “null” for ribbons

    document.GetElementById will not work as the DOM has been changed. Try setting the legacy form rendering to true by going to the system settings.

  • Community Member Profile Picture
    on at
    RE: document.getElementById always returns “null” for ribbons

    please use Window.parent.document.getElementById

    hope it works

    Please mark verified if it suits your query!!1

    Regards,

    Nithin

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans