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)

FormattedValues not working for inactive reocrds

(0) ShareShare
ReportReport
Posted on by

Hi,

after upgrading CRM from 8.2 to v9 I've found a weird issue with a linq query in the c# code.

Working fine with v8.2 but for v9 it only works for Active records, not sure why it fails for Inactive.

StatusReason = r.FormattedValues["statuscode"]

And the error is: The given key was not present in the dictionary    System.Exception System.Collections.Generic.KeyNotFoundException

 

Any help on this?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: FormattedValues not working for inactive reocrds

    Hi,

    You could retrieve the attribute metadata in the cases that the attribute is not available as a formatted value

    //Given field is available as an formatted value
    if (r.FormattedValues.contains("statuscode") {
        StatusReason = r.FormattedValues["statuscode"]
    }
    else {
        //Retrive attribute metadata to get the label for statuscode
        var attributeRequest = new RetrieveAttributeRequest
        {
            EntityLogicalName = r.LogicalName,
            LogicalName = "statuscode",
            RetrieveAsIfPublished = true
        };
    
        var attributeResponse = (RetrieveAttributeResponse)service.Execute(attributeRequest);
        var attributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata != null ? (EnumAttributeMetadata)attributeResponse.AttributeMetadata : null;
    //This is only an example of how to handle the metadata retrieved for OptionSets List<KeyValuePair<string, int?>> optionMetadataList = new List<KeyValuePair<string, int?>>(); foreach (OptionMetadata option in attributeMetadata.OptionSet.Options) { optionMetadataList.Add(new KeyValuePair<string, int?>(option.Label.UserLocalizedLabel.Label, option.Value)); } //Do something with the metadata retrieved }


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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans