I have several of these instances I have to call to pull down data from a crm server.
RetrieveAttributeRequest request = new RetrieveAttributeRequest();
request.EntityLogicalName = "opportunity";
request.LogicalName = "new_businessunit";
RetrieveAttributeResponse response = (RetrieveAttributeResponse)lService.Execute(request);
PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;
RetrieveAttributeRequest requestsource = new RetrieveAttributeRequest();
requestsource.EntityLogicalName = "opportunity";
requestsource.LogicalName = "new_sourcepick";
RetrieveAttributeResponse responsesource = (RetrieveAttributeResponse)lService.Execute(requestsource);
PicklistAttributeMetadata picklistsource = (PicklistAttributeMetadata)responsesource.AttributeMetadata;
Dictionary<int?, string> BusinessUnits = new Dictionary<int?, string>();
foreach (OptionMetadata option in picklist.OptionSet.Options)
{
string picklistlabel = option.Label.UserLocalizedLabel.Label.ToString();
businessid = option.Value;
BusinessUnits.Add(businessid, picklistlabel);
}
Dictionary<int?, string> MarketSegment = new Dictionary<int?, string>();
foreach (OptionMetadata option in picklistmarket.OptionSet.Options)
{
string picklistlabel = option.Label.UserLocalizedLabel.Label.ToString();
marketid = option.Value;
MarketSegment.Add(marketid, picklistlabel);
}
So basically I pull the data down and then build a dictionary to hold the data. I have a lot of these so I would like to make a method where I just pass the EntityLogialName and the LogicalName. So instead of having all that I could do something like:
loadlist(opportuniuty, new_businessunit)
But I’m not really sure how to make the method to handle it. Any ideas on how I would do the method?
Thanks!
Encapsulate the loading of any data within a method, and call it twice (once for each set of data you’re interested in). The above uses LINQ to translate the
Optionsinto aDictionaryusing theToDictionaryextension method.