I am using following code to get localized label for option set but its returning null exception. Following line of code returns null when passed 1025 which is language code for Arabic.
oMD.Label.LocalizedLabels.Where(x => x.LanguageCode == lcid)
I am using Dynamics CRM 2016 On-Prem and Arabic language pack is installed and enabled.
try
{
if (lcid == 0)
lcid = 1033;//1025
using (var xrmContext = new XrmServiceContext(CRMConnection.CRM))
{
RetrieveAttributeRequest raRequest = new RetrieveAttributeRequest
{
EntityLogicalName = entityName,
LogicalName = optionSetName,
RetrieveAsIfPublished = true
};
RetrieveAttributeResponse raResponse = (RetrieveAttributeResponse)xrmContext.Execute(raRequest);
PicklistAttributeMetadata paMetadata = (PicklistAttributeMetadata)raResponse.AttributeMetadata;
OptionMetadata[] optionList = paMetadata.OptionSet.Options.ToArray();
Dictionary<int, string> dic = new Dictionary<int, string>();
foreach (OptionMetadata oMD in optionList)
{
dic.Add((int)oMD.Value, oMD.Label.LocalizedLabels.Where(x => x.LanguageCode == lcid).FirstOrDefault().Label.ToString());
}
return dic;
}
}
catch (Exception e)
{
LogHelper.LogException(e, "LocalOptionSetList - IntegrationManager");
throw new Exception(e.ToString());
}
Any help please...
*This post is locked for comments
I have the same question (0)