Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

How to set (SET) a custom 'option set' in a custom field?

$
0
0

//this snipped is for getting.....

var _entityName = "systemuser"; //user
var fieldName = "new_officetype"; //option set field

RetrieveEntityRequest entityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.All,
LogicalName = _entityName,
RetrieveAsIfPublished = true
};

// Get the Response and MetaData. Then convert to Option MetaData Array.
RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)_orgService.Execute(entityRequest);
EntityMetadata metadata = entityResponse.EntityMetadata;
PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, fieldName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;
OptionSetMetadata optionsSetMet = picklistMetadata.OptionSet;
var optionlist = (from o in optionsSetMet.Options
select new { Value = o.Value, Text = o.Label.UserLocalizedLabel.Label }).ToList();
foreach (var item in optionlist)
{
Console.WriteLine(item.Text + " " + item.Value);
}


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>