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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

MUI HTML text in a form. context.getUserLcid(); is not working.

(0) ShareShare
ReportReport
Posted on by 170

Hello CRM colleagues, 

I've never worked with JS in CRM before. I'd like to display a text in a form using an HTML field that would show a text according to the users local CRM language. The test code below works just fine, but once I replace var userLcid = 1033; with var userLcid = context.getUserLcid();, the code does not work anymore, no text is displayed. What have I done wrong? What would you do to make it work?

I tried :

  • context.getUserLcid()
  • getUserLcid()
  • window.Xrm.Page.context.getUserLcid()
  • Xrm.Page.context.getUserLcid()
  • Convert.ToInt32(window.Xrm.Page.context.getUserLcid())

<html><head><meta charset="utf-8"></head>

<body>
<local id="Hinweis"></local>

<script>
var userLcid = 1033; //context.getUserLcid();

var localizedStrings = {
Hinweis: {
_1033: "English text",
_1031: "Deutscher Text"
} };
var LocalizedHinweis = localizedStrings.Hinweis["_" + userLcid];
document.getElementById("Hinweis").innerHTML = LocalizedHinweis ;
</script>

<br>
</body></html>

*This post is locked for comments

I have the same question (0)
  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     if you are using a webresource, here is how you can get access to the context:

    msdn.microsoft.com/.../gg328541.aspx

  • Suggested answer
    Mihir Maruti Kadam Profile Picture
    702 on at

    In your HTML code use this function to access URL parameter and then you will get userLCID. 

    Xrm.Page.context.getQueryStringParameters()

     userLCID.png

  • Hikmat Daghestani Profile Picture
    170 on at

    Sorry, I tried to apply your answers, it didn't work either, how exactly should my code look like with this modification?

    @Mihir:  I tried

    var userLcid = Xrm.Page.context.getQueryStringParameters();

    It didn't work.

    @Alex: I tried the page you suggested, it was insightful, I tried adding the following function to my script:

    function context.getUserLcid() {

    var errorMessage = "Context is not available.";

    if (typeof GetGlobalContext != "undefined")

    { return GetGlobalContext(); }

    else

    {

     if (typeof Xrm != "undefined") {

      return Xrm.Page.context;

     }

     else { throw new Error(errorMessage); }

    }

    }

    It didn't work.

    I tried:

    <script src="../ClientGlobalContext.js.aspx" type="text/javascript" ></script>

    instead of

    <script></script>

    did't work either.

  • Hikmat Daghestani Profile Picture
    170 on at

    You are right, it worked.

    Thanks Guido & Alex.

    And thank you Mihir for trying to help.

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

News and Announcements

Season of Giving Solutions is Here!

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