Obtaining a list of option values for a MS CRM 2011 OptionSet is pretty simple, especially if you plan to do this via the CRM Web service API. However a requirement may arise where you may want to do this using direct SQL against the Organization database.
Example Background
By default on the account entity there are several address fields, and one in particular is the Address Type picklist which is used to categorize the type of address stored for this account. Using this field as an example, the following SQL Query can be used to obtain a list of all options available to that field:
SQL Statement
- SELECT
- EV.LogicalName as Entity,
- ALV.Name as Attribute,
- LLV.Label,
- APV.Value
- FROM LocalizedLabelView as LLV
- INNER JOIN AttributePicklistValueView as APV ON LLV.ObjectId = APV.AttributePicklistValueId
- INNER JOIN OptionSetView as O ON APV.OptionSetId = O.OptionSetId
- INNER JOIN AttributeLogicalView as ALV ON O.OptionSetId = ALV.OptionSetID
- INNER JOIN EntityView as EV ON ALV.EntityId = EV.EntityId
- WHERE
- ALV.Name like '%address1_addresstypecode%' AND EV.LogicalName = 'account'
- ORDER BY EV.LogicalName, ALV.Name, APV.Value
Enjoy :)
No comments:
Post a Comment