web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 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
    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
    437 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
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans