C# Dynamics CRM Get status code metadata

The following code snippet will help you to get all option set value and label of entity state and status.

Get state code metadata (statecode)

RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest { EntityLogicalName = "account", LogicalName = "statecode", RetrieveAsIfPublished = true }; RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse) service.Execute(attributeRequest); AttributeMetadata attrMetadata = attributeResponse.AttributeMetadata; StateAttributeMetadata statusMetadata = (StateAttributeMetadata) attrMetadata; column.Options = new List < Option > (); foreach(StateOptionMetadata optionMeta in statusMetadata.OptionSet.Options) { string label = optionMeta.Label.UserLocalizedLabel.Label; int value = (int) optionMeta.Value; }
Code language: PHP (php)

Get status code metadata(statuscode)

RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest { EntityLogicalName = "account", LogicalName = "statuscode", RetrieveAsIfPublished = true }; RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse) service.Execute(attributeRequest); AttributeMetadata attrMetadata = attributeResponse.AttributeMetadata; StatusAttributeMetadata statusMetadata = (StatusAttributeMetadata) attrMetadata; column.Options = new List < Option > (); foreach(StatusOptionMetadata optionMeta in statusMetadata.OptionSet.Options) { string label = optionMeta.Label.UserLocalizedLabel.Label; int value = (int) optionMeta.Value; }
Code language: PHP (php)

Leave a Reply