Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Execute a customize function (javascript) when close an opportunity

(1) ShareShare
ReportReport
Posted on by 201

Hi,

I have a new field in my opportunities entity, and i need evaluete if this new field have a value when i close the opportunity (Won or Lost) and if this field don't have value don0t let me close the opportunitie.

Anyone can tell me how i can execute my customized function in this specific action?!

Thanks!

*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Execute a customize function (javascript) when close an opportunity

    Yes. You will have to use 2 override functions.

  • Victor Parada Profile Picture
    Victor Parada 201 on at
    RE: Execute a customize function (javascript) when close an opportunity

    Hi Andrii,

    Thanks alot for this topic, i go to deploy this solution.

    How you identify when the action is to close as Won or close as Lost???

    I'm need to create two JS functions? what is you recomendation?!!!

  • Victor Parada Profile Picture
    Victor Parada 201 on at
    RE: Execute a customize function (javascript) when close an opportunity

    Hi Himbap,

    Thanks for you reply, that is my first idea but is not a best idea because the performance of the system, for that i want to deploy a javascript solution.

    Thanks.

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Execute a customize function (javascript) when close an opportunity

    Another possible option could be to use a real time workflow which will run on status change and you can check if that field is missing some value cancel workflow with error message ??

    Hope it will help.

    Thanks

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Execute a customize function (javascript) when close an opportunity

    Hello,

    I implemented this scenario for my customer this week so I can share with my results:

    1. You will have to customize commands of standard buttons - ribbonworkbench.uservoice.com/.../81981-2-customising-standard-ribbons

    2. Let's take Win button as an example. Create JS webresource that will contain following code:

       function winOverride() {

           if (true){//add your validation logic here

                   Xrm.Utility.alertDialog("Opportunity can't be closed as won because....", function(){});

                   return;

           }

           Mscrm.OpportunityCommandActions.opportunityClose(true);

       }

    3. Replace reference of function that is used in Win button command with reference to function provided in previous point.

    4. Save and publish your ribbon.

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,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans