Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Pretty much everything is in the title.

If you know how to do, please tell me!

Thank You.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    This is the code I wrote, following what I read online :

    function deactivateMission(executionContext){

     var formContext = executionContext.getFormContext();

     formContext.data.entity.attributes.foreach(function(attribute,index){

       var control = formContext.getControl(attribute.getName());

       if (control){

         control.setDisabled(true);

       }

     })

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    Help me please! :D

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    Hello Again! Sorry, I was on holidays.

    You told me to let you know if I needed more details on the "formContext parameter", and I do!

    Should I use it like I would use Xrm.Page?

    Thank You

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    I'll definitely check this out in the following days, thanks a lot for your precious help.

  • Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    Ok, for some context here, evey custom entity has the 'Status' field.
    Once you set this to 'Inactive', the form is automatically made read-only by the system.
    So, this would be one way to ensure that your users cannot 'modify' the record anymore once you 'Close' it.
    However, in most scenarios, you would want to leave your record status as 'Active', but make the record read-only.
    To achieve this, do the following:
    1. Open up the fields for the entity you are working with.
    2. Find the 'Status Reason' field and add the new options you want there such as 'Close' / 'Lost' etc.
    Here is some background reading on Status and Status Reason.
    https://community.dynamics.com/crm/b/briteglobalsolutions/archive/2017/09/11/status-and-status-reason-in-dynamics-crm

    Once you have defined the new statuses, you would need to create a JavaScript library which has a function that checks the record's status and locks all the fields on the form. (eg: If record status is Lost/Closed, make all the fields locked, so that users cannot modify them)
    This is the core snippet you need to use: https://stackoverflow.com/questions/28169295/disabling-all-fields-on-a-form-in-crm-2015
    But instead of 'Xrm.Page', use the formContext parameter (let me know if you need more details on this.)
    In case you are not familiar with using JavaScript and WebResources, this would be a good place to start: https://msdn.microsoft.com/en-us/library/gg328261.aspx
    Ensure that the JavaScript function is called OnLoad of the form.

    So now you have the Statuses and the Script file, all you need are the custom buttons on your form.
    Simply put, once you click the buttons (Close / Lost), then:
    1. Set the status field accordingly
    2. Save the record using JavaScript.
    2. Call the field-locking function (if required.)

    Use the Ribbon Workbench solution to create the buttons and link your JavaScript functions to these buttons.
    Follow the steps mentioned here to get this done.
    https://ribbonworkbench.uservoice.com/knowledgebase/articles/71374-1-getting-started-with-the-ribbon-workbench

    If you are new to all this, there is a small learning curve. But feel free to ping back for any queries!

    Happy XRM'ing. Cheers!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    So yeah, for the moment, I just want to add a Close button, so the entity cannot be modified anymore, and if possible specify if the process was finished or aborted.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    I'll probably go with option 1 for the moment, I'm not really sure about what I should do yet.

    Ideally I would have similar buttons you can find in the opportunity entity, but maybe just the close one, with different images, I really don't know yet, I have to think about it.

  • Verified answer
    Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Is it possible to add the option "Close as Lost" or "Close as Won" available in Opportunities to a custom entity?

    You question is very open-ended. Could you please elaborate on specifics?


    But here are some scenarios:

    1. If you just want the same buttons you see on the Opportunity record, YES.
    Use the excellent 'Ribbon WorkBench' and create the same buttons.
    Have your own custom javascript which decides what action has to take place when you click those buttons.

    2. Are you looking for the nice pop-up boxes you see when you click those buttons on the Opportunity record?
    Again, YES. This is possible, but you have to build your own HTML web-resource which looks that way, as well as have your own
    event handlers for the buttons.
    The OOB pop-up writes to the OpportunityClose entity. In your case, you will not be doing this.

    Let me know more specifics and I can help you with more info.

    Cheers!

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,401 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans