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 :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 437

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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    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

  • windyMill Profile Picture
    437 on at

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

  • Suggested answer
    Community Member Profile Picture
    on at

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

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

    {

    //opp is won

    }

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    Try the code below.

     if (context.InputParameters.Contains("Target") &amp;&amp;
                    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.

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans