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)

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

    Hi Abdul,

    why do you need js code for this? You can disable even only one button using Ribbon Workbench.

    Regards, Karan

  • Verified answer
    Bas van de Sande Profile Picture
    4,383 on at

    Hi Abdul,

    you can write any javascript you want, however keep in mind that the function needs to return true or false.  A value of true will result in the Enabling of the button, false will Disable it.

    I hope this helps you forward

    Bas

  • Verified answer
    Alagunellaikumar Profile Picture
    6,212 on at

    HI

    Please refer below URL

    garethtuckercrm.com/.../dynamically-disable-ribbon-buttons-in-dynamics-crm

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Bas van de Sande and Karan5959 and all

    I need just a line of code not more than that. Please give it to me.

    Thank You

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Alagu nellaikumar.S

    Sorry this is not What I need. Please give me a line of code.

    Thank You

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi, 

    Please refer this link: https://community.dynamics.com/crm/f/117/t/221915

    M
    y answer in that post might help you.

    Regards,

    Please verify if it helps

  • Suggested answer
    Community Member Profile Picture
    on at

    function disableButton() {

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

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

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

    }

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Ezgi HAGLUND

    Hi You code giving me this error

    0284.aaa.jpg

  • Verified answer
    Community Member Profile Picture
    on at

    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

  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at

    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

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