Retrieve Metadata of a Boolean (Two Options) Attribute in Microsoft Dynamics CRM 2011/2013

Code to retrieve the boolean (Two Options) attribute metadata in CRM 2011. You need to pass the boolean value to get the Text.

public static string GetBoolText(IOrganizationService service, string entitySchemaName, string attributeSchemaName, bool value)
            RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
                EntityLogicalName = entitySchemaName,
                LogicalName = attributeSchemaName,
                RetrieveAsIfPublished = true
            RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
            BooleanAttributeMetadata retrievedBooleanAttributeMetadata = (BooleanAttributeMetadata)retrieveAttributeResponse.AttributeMetadata;
            string boolText = string.Empty;
            if (value)
                boolText = retrievedBooleanAttributeMetadata.OptionSet.TrueOption.Label.UserLocalizedLabel.Label;
                boolText = retrievedBooleanAttributeMetadata.OptionSet.FalseOption.Label.UserLocalizedLabel.Label;
            return boolText;


Popular posts from this blog

Workflow Activity Input and Output Parameters and Data Types in MS CRM 2013/15/16

Get Workflow Guid in Javascript using OData query

Convert Plugin to Sandbox mode,