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)

Javascript code to disable button

(1) ShareShare
ReportReport
Posted on by 12,119 Moderator

Hi all

I need JS code to disable my button. I know workbench disable functionality. I only need js code line which disable my custom button.

Thank You

*This post is locked for comments

I have the same question (0)
  • Abdul Wahab Profile Picture
    12,119 Moderator on at
    RE: Javascript code to disable button

    Hi Nithya Gopinath

    Thank You. My requirement is not this but as @Ezgi HAGLUND suggest me the solution. So now this is my solution.

    Thank You

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Javascript code to disable button

    Hi Abdul wahab,

    Have you referred the link below?

    stackoverflow.com/.../crm-2011-how-to-hide-show-the-ribbon-button-with-javascript

  • Abdul Wahab Profile Picture
    12,119 Moderator on at
    RE: Javascript code to disable button

    Hi Ezgi HAGLUND

    No it is not doing anything. What can I do now?

    Thank You

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Javascript code to disable button

    top.document.getElementById("salesorderdetail|NoRelationship|Form|btnRejectDiscount-Medium").disabled = true;        

    Can you try this? (sorry for misunderstanding)

  • Abdul Wahab Profile Picture
    12,119 Moderator on at
    RE: Javascript code to disable button

    Hi Ezgi HAGLUND

    My code is also working but it is hiding the button. I need to diable it. Please do let mo know. How may I disable it?

    Thank You

  • Abdul Wahab Profile Picture
    12,119 Moderator on at
    RE: Javascript code to disable button

    Hi Ezgi HAGLUND

    Your code hiding my button. I want to disable it. Please tell me How can I disable it.?

    Thank You

  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at
    RE: Javascript code to disable button

    Hi Abdul,

    you cannot access the DOM directly, you need to use the Xrm.Page object model.

    that's why you get the error.

    in you library you can wrte a javascript function like

    function foo() {

    var field = Xrm.Page.getAttribute('logicalfieldname').getValue();

    return (field=='Some Value');

    }

    that's all it takes

    Bas

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Javascript code to disable button

    this is my code that works well:

    top.document.getElementById("salesorderdetail|NoRelationship|Form|btnRejectDiscount-Medium").style.display = 'none';     

    and this is the id where I got from F12:

    8686.Ekran-Al_3101_nt_3101_s_3101_.PNG

  • Abdul Wahab Profile Picture
    12,119 Moderator on at
    RE: Javascript code to disable button

    Hi Ezgi HAGLUND

    Hi You code giving me this error

    0284.aaa.jpg

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Javascript code to disable button

    function disableButton() {

       var field = Xrm.Page.getAttribute('fieldName').getValue();

       if (field == XY) { return true; }

       if (field != XY) { return false; }

    }

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans