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

Announcements

No record found.

News and Announcements icon
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)
  • Community Member Profile Picture
    on at

    please use Window.parent.document.getElementById

    hope it works

    Please mark verified if it suits your query!!1

    Regards,

    Nithin

  • Suggested answer
    Community Member Profile Picture
    on at

    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.

  • ScottDurow Profile Picture
    21 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans