Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to check opportunity is open , close , won and lost

Posted on by 435

Hi Guys,

I m writing a plugin in which is need to check weather oppurtunity is open , close , won or lost .

pls help 

Thsnks

*This post is locked for comments

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How to check opportunity is open , close , won and lost

    Hi,

    Try the code below.

     if (context.InputParameters.Contains("Target") &&
                    context.InputParameters["Target"] is Entity)
                {
                    // Obtain the target entity from the input parameters.
                    Entity entity = (Entity)context.InputParameters["Target"];
    
                    // Verify that the target entity represents an opportunity.
                    // If not, this plug-in was not registered correctly.
                    if (entity.LogicalName != "opportunity")
                        return;
                    try
                    {
                      int stateCode = GetAttributeValue<OptionSetValue>("statecode").Value;
                      if(stateCode == 0)
                      {
                         //Open Opportunity
                      }
                      if(stateCode  == 1)
                      {
                         //Won Opportunity
                      }
                      if(stateCode  == 2)
                      {
                         //Lost Opportunity
                      }
                    }
                }

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to check opportunity is open , close , won and lost

    get the opportunity entity record store it in a variable (for ex. objOpp).

    if(objOpp.GetAttributeValue<OptionSet>("statecode").Value == 1)

    {

    //opp is won

    }

  • windyMill Profile Picture
    windyMill 435 on at
    RE: How to check opportunity is open , close , won and lost

    can you give me C# code to check weather oppurtunity is closed or open  

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to check opportunity is open , close , won and lost

    Check Status(statecode) and Status Reason(statuscode) field values in your plugin.

    Values can be found from this link

    https://technet.microsoft.com/en-us/library/dn531157.aspx

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans