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;
}
else
{
boolText = retrievedBooleanAttributeMetadata.OptionSet.FalseOption.Label.UserLocalizedLabel.Label;
}
return boolText;
}
No comments:
Post a Comment