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 :
Customer experience | Sales, Customer Insights,...
Answered

How To disable CloseAsWon button with XrmToolBox

(0) ShareShare
ReportReport
Posted on by 448

Hi all

I'm trying to disable button "CloseAsWon" in opportunity, with XrmToolBox.

The button must be disabled until the value of field [opportunity][stepname] not equal to value "4-Chiudi"

I follow this example "ribbonworkbench.uservoice.com/.../121427-enable-disable-a-ribbon-button-dynamically-based-o" but I'm not able to find the way.

This is my screenshot

pastedimage1672915699931v1.png

where I'm mistaken?

I have the same question (0)
  • Suggested answer
    Mohamed GRAIB Profile Picture
    2,504 Moderator on at

    Hi Die,

    function HidecloseaswonButton() {

        // Query for full name of the current user

        var stepname = Xrm.Page.context.getstepname();

       if(stepname== '---some Id---')

       {

           return true;

       }

       else

       {

           return false;

       }

    }

    You can follow this Link.

    Hope that's helpful for you.

    please mark the answer as verified if that's helpful for you

  • DiePic Profile Picture
    448 on at

    thanks a lot Mohamed GRAIB

    but there is for sure a way with the tool

  • DiePic Profile Picture
    448 on at

    using information on this post (https://balugajjala.wordpress.com/2017/01/27/enabledisable-a-ribbon-button-dynamically-based-on-a-form-value/)

    I try to add a rule to the button MarkAsWon 1st picture

    pastedimage1672928294515v2.png

    this is the script

    pastedimage1672928373114v3.png

    but it get me an error

    pastedimage1672928504076v5.png

    error on getFormContext ???? .... where I'm mistaken?

    thenks in advance for help or suggestion

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Pass PrimaryControl which will act as the Execution Context.

    Pass data from a page as a parameter to Ribbon actions (model-driven apps) - Power Apps | Microsoft Learn

    pastedimage1672928787824v1.png

    Thanks,

    Amit Katariya

  • DiePic Profile Picture
    448 on at

    Hi Amit Katariya007  and thanks for your help

    now after insert PrimaryControl, the error change as follow

    pastedimage1672929914528v2.png

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Refer below article where we can use custom rule and invert the result.

    balugajjala.wordpress.com/.../

    below article will help you to use primary control for ribbon js

    blog.magnetismsolutions.com/.../getting-dynamics-365-formcontext-from-ribbon-workbench

    Thanks,

    Amit Katariya

  • DiePic Profile Picture
    448 on at

    Hi Amit Katariya007 

    thanks for your help but this is over my knowledge ... the script is correct as in posts, but return always an error ... maybe because MarkAsWon is a system button?

    pastedimage1672933681266v1.png

    As you can see in picture I substitute the retrive command with the variable that I espect to find with retrieve command ... so is working

    pastedimage1672932440250v1.png

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    Use below code to get value

    Var stepnamevalue=executionContext.getAttribute("stepname").get value();

    And leave below code commented

    //Var formContext=execution context.getFormContext();

  • DiePic Profile Picture
    448 on at

    Hi Bipin Kumar  and thanks for your help.

    In your way dont give more errors, but it's not retriving data and form remain unchanged.

    this is the summary after a lot of attempts:

    - XrmToolBox

    pastedimage1672934998404v1.png

    - script

    pastedimage1672935038733v2.png

    thanks in advance for any help

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Don't use space between getValue function. U have used as get Value, that is incorrect

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 > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 184 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 125

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans