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)

Getting case status text using c#

(0) ShareShare
ReportReport
Posted on by

Hi 

I am trying to get case status text like resolved or active by using below code, but getting error. Thanks

string status = ent.FormattedValues["statecode"].ToString();

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Are you retrieving this via Plugin?

    How are you referencing ent (is it using InputParameters["Target"], Pre/Post Entity Images).

    If you are using InputParameters["Target"], you might have to actually retrieve the data using a Retrieve method:

    string entityName = localContext.PluginExecutionContext.PrimaryEntityName;

    Guid entityId = localContext.PluginExecutionContext.PrimaryEntityId;

    Entity ent = service.Retrieve(entityName, entityId, new ColumnSet(true));

    Hope this helps.

  • Suggested answer
    Iswarya Profile Picture
    1,347 on at

    Hi,

    try this one i have tested this

    string Statetext= entity.FormattedValues["statecode"];

  • NKC Profile Picture
    on at

    Below is the code i am using getting key not present in the dictionary for status

    EntityCollection EC = service.RetrieveMultiple(QE);

                   int total = EC.Entities.Count;

                   Console.WriteLine(total);

                   if(EC.Entities != null)

                       {

                       foreach(var ent in EC.Entities)

                           {

                           string casenumber = ent["ticketnumber"].ToString();

                           string casetitle = ent["title"].ToString();

                           Guid  caseid = Guid.Parse(ent["incidentid"].ToString());

                           string id = caseid.ToString();

                         // Console.WriteLine("{0}\t{1}\t{2}", ++recordcount, casenumber, casetitle);

                           Entity resolution = new Entity("incidentresolution");

                           resolution["subject"] = "Closed";

                           resolution["incidentid"] = new EntityReference(ent.LogicalName,caseid);

                           CloseIncidentRequest closecase = new CloseIncidentRequest();

                           closecase.IncidentResolution = resolution;

                           closecase.Status = new OptionSetValue(5);

                           CloseIncidentResponse closeresponse = (CloseIncidentResponse)_service.Execute(closecase);

                           string status = ent.FormattedValues["statecode"];

                           Console.WriteLine("{0}\t{1}\t{2}\t{3}", ++recordcount, casenumber, casetitle,status);

                           }

                       }

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    Hi Krish,

    Make sure you are declaring the 'statecode' field in column set/attribute list.

    If you are using Query Expression then mention the 'statecode' field schema name in columnset property (like : queryObj.ColumnSet = new ColumnSet("statecode");

    If you are using Fetch XML then add the 'statecode' column before downloading the fetch xml (iike: <atribute name="statecode"/>)

    Hope it resolve your issue. mark it verified if it helps.

    Cheers

    Arpit

  • Zibba360 Profile Picture
    on at

    Hi Krish

    Please share code, how are you retrieving the entity. I faced a similar issue because I had 2 organization service references in different classes. It seems like there is no value (it's null...to make sure it's null or not, use ent.GetAttributeValue<string>("statuscode")).

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi krish,

    im pretty sure you missed "statecode" value from retrieve ColumnSet.

    Please modify your column set to include it, like new ColumnSet("new_field1", "new_field2", "statuscode", "statecode");

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi krish,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans