June 26, 2013
XRM: Bind a CRM Option Set to a DropDownList
This Method bind a CRM option set to a DropDown List ( The Option Set would reference a field in a specific entity )
public static void fillOptionsList(IOrganizationService service, string EntityLogicalName,
string fieldName, DropDownList optionSetList)
{
try
{
RetrieveAttributeRequest retrieveAttributeRequest =
new RetrieveAttributeRequest
{
EntityLogicalName = EntityLogicalName,
LogicalName = fieldName,
RetrieveAsIfPublished = true,
};
// Execute the request.
RetrieveAttributeResponse retrieveAttributeResponse =
(RetrieveAttributeResponse)service.Execute(
retrieveAttributeRequest);
// Access the retrieved attribute.
PicklistAttributeMetadata retrievedPicklistAttributeMetadata =
(PicklistAttributeMetadata)
retrieveAttributeResponse.AttributeMetadata;
// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
//Dictionary<int,string> LocalizedLabelDic = new Dictionary<int,string>();
//List<ListItem> OptionSetItems = new List<ListItem>();
foreach (OptionMetadata o in optionList)
{
optionSetList.Items.Add
(new ListItem(o.Label.LocalizedLabels.FirstOrDefault().Label, o.Value.Value.ToString()));
}
}
catch (Exception e)
{
//Logger.LogException(e);
}
}
Exporting Single Entities using CRMSvcUtil tool
In the last days while working on a CRM customization project that interacts with SharePoint web parts, while refactoring the code, I thought of trying to minimize the size of the file generated originally by the CRMSvcUtil by only choosing the needed entities in my solution. The generated file was almost 5MB in size which is a very big load to the system, but apparently in CRM SDK 2011 microsoft removed the parameter called Entity to specify specific entities. Then I searched the web and found this great post that give a perfect, simple, and working solution for this issue
http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html
http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html
Subscribe to:
Posts (Atom)