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

Notifications

Announcements

No record found.

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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans