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)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 }
Community Member
2
Christoph Pock
1