web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to get localized label for optionset

(0) ShareShare
ReportReport
Posted on by 385

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)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please confirm that labels are returned and available in response you get?

  • abdulghaffar164 Profile Picture
    385 on at

    Hi @Andrew

    Thanks for the reply,

    Yes labels are returned. Even LocalizedLabel for English is also listing as you can see in below image. The problem is it is returning only base language localizedlabel which is English. I want Arabic language labels.

    34038.Capture.PNG

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Is it a custom field?

    Can you please confirm that you have localized value for that picklist in-place?

  • abdulghaffar164 Profile Picture
    385 on at

    Yes it is a custom field. How to setup up localized value because I have created an optionset containing two options as we normally do. The optionset is called "MaritalStatus" and it contains two options 1)Single 2)Married

  • Verified answer
    Peter72 Profile Picture
    1,815 on at

    Hi Abdul

    I guess what Andrew meant was: do you have added the translation for "Single" and "Married"? You can do that with "Export Field Translations". You get a column for each installed language. After translation, "Import Field Translations". After that, your code should return the expected localized labels.

    ExportFieldTranslations.png

    Best Regards

    Peter

  • abdulghaffar164 Profile Picture
    385 on at

    Hi @Peter

    Thanks, yes exporting and re-importing the translation solved the issue.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans