web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

I am not find the way to get status value

(0) ShareShare
ReportReport
Posted on by 1,562

I am using:
Entity Opportunitystatus = (Entity)crmService.Retrieve("opportunity", new Guid(opportunity.Attributes["opportunityid"].ToString()), new ColumnSet(allColumns: true));
                         
string statustest  = Opportunitystatus.Attributes["statecode"].ToString()

OUTput:
Microsoft.Xrm.Sdk.OptionSetValue

How i can check the opportunity status is open/lost mode.

*This post is locked for comments

I have the same question (0)
  • Royal King Profile Picture
    27,686 on at

    use below code to get statuscode  ( Status reason)

    var statustest  = Opportunitystatus.Attributes<OptionSetValue>["statuscode"];

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Rahul,

    You need to parse it and cast to the OptionSetValue

    int statecode = Opportunitystatus.Attributes<OptionSetValue>["statecode"].Value;

    int statuscode = Opportunitystatus.Attributes<OptionSetValue>["statuscode"].Value;

    Then you will get the number

    Which you can compare:

    msdynamicscrmblog.wordpress.com/.../status-and-status-reason-values-in-dynamics-crm-2013

    if (statecode == 0)

    {

       //Open

    }

    else if (statecode == 1)

    {

       //Won

    }

    else if (statecode == 2)

    {

       //Lost

    }

    Hope this helps.

    THanks.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Just check:

    if(Opportunitystatus.GetAttributeValue<OptionSetValue>("statecode").Value==0)

    {

    //it's open

    }

    else

    {

    //not open

    }

    Thanks

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans