Monday, March 9, 2015

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;

No comments:

Post a Comment

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...