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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Send email depending on user language

(0) ShareShare
ReportReport
Posted on by

Hi,

I currently have a fully bilingual(English and French) CRM interface. The user can choose the language that he/she wants.

Every time the user submit something, a confirmation email is sent to him.
The email is sent by a C# script that I wrote. The only problem is that the email is always sent in English but I want to make it so it sends it in the language of the user.

How do I check what is the current language so I can make two different message?

Feel free to ask any questions

Thank you.



*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi Philippe,

    You can get the langauage code from the usersettings entity like this:

    Entity userSettings = service.RetrieveMultiple(
        new QueryExpression("usersettings")
        {
            ColumnSet = new ColumnSet("uilanguageid"),
            Criteria = new FilterExpression
            {
                Conditions =
                {
                    new ConditionExpression("systemuserid", ConditionOperator.Equal, systemUserId)
                }
            }
        }).Entities.FirstOrDefault();
    if (userSettings != null && userSettings.Contains("uilanguageid"))
    {
        // This is the 
        // userSettings["uilanguageid"]
    }


    The language id will correspond to the decimal identifier for a language pack listed here: https://technet.microsoft.com/en-us/library/cc722435(v=ws.10).aspx

    English is 1033, French is 1036.

    Hope this helps! I'd appreciate if you'd mark this as a Verified answer.

    Thanks,

     Aiden

    (edited for a typo)

  • Community Member Profile Picture
    on at

    Thank you for your answer.

    Could you explain the code a little more? This is hard for me to understand how to implement this code in my solution.

    Also my plugin that send the email is in C# but the code you have put there looks like JavaScript? (I'm not sure) how can I add a condition in my plugin that checks the uilanguageid?

  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi Phillippe,

    That's C#. In your plugins, you have access to an organization service to interact with CRM. This section is creating a new QueryExpression for the "usersettings" record, getting back the "uilanguageid" column for a system user (systemUserId would be the ID of your user). The query returns an Entities collection, so I'm getting back just the first one. The settings for your user will be in the userSettings Entity object:

    Entity userSettings = service.RetrieveMultiple(

       new QueryExpression("usersettings")

       {

           ColumnSet = new ColumnSet("uilanguageid"),

           Criteria = new FilterExpression

           {

               Conditions =

               {

                   new ConditionExpression("systemuserid", ConditionOperator.Equal, systemUserId)

               }

           }

       }).Entities.FirstOrDefault();

    After the query, you can check there's a record returned and a language using this if conditon:

    if (userSettings != null && userSettings.Contains("uilanguageid"))

    and if there's a record and it has a value, get the value from entity like this:

    int languageCode = int.Parse(userSettings["uilanguageid"].ToString()));

    Then you can compare the language code against the known language codes and send out the email appropriately.

    Hope this helps, let me know if you have any more questions. I'd appreciate if you'd mark this as a verified answer.

    Thanks,

     Aiden

  • Community Member Profile Picture
    on at

    Sorry if I'm asking too many questions, but when I copy your code I get a bunch of errors. For my other connection I was using this way to query to get the information. I'm not sure what is the best way to do it but it's the only way I know

     initiatingUser = context.CreateQuery<SystemUser>().Single(x => x.Id == localContext.PluginExecutionContext.InitiatingUserId);


  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi,

    There's nothing wrong with asking questions. Here's a good link on how to create a simple plugin in C# and it's the style I use in my code: msdn.microsoft.com/.../gg594416.aspx

    Most of the way down the code, there's a line:

    IOrganizationService service ....

    This is the "service" that's being used in my code.

    An easier way to implement this may be as a custom workflow step, because you can trigger the workflow on that record being submitted. With a custom workflow assembly you don't need to worry about setting the plugin image correctly or worrying about the entity, you can configure the workflow to run when you want it and check for the right status. Here's a really good example of writing a custom workflow activity: msdn.microsoft.com/.../gg334455.aspx If you went that route, you could copy almost all your plugin code to the new assembly and it would work with just a few tweaks.

    Hope this helps, let me know if you have any more questions. I'd appreciate if you'd mark this as a verified answer.

    Thanks,

    Aiden

  • Community Member Profile Picture
    on at

    Thank you very much for your help. Right now I'm getting this error: The type or namespace name 'QueryExpression' could not be found (are you missing a using directive or an assembly reference?

    What does that mean? uiuilanguageid is still returning 0 but I'm getting closer

  • Community Member Profile Picture
    on at

    Never mind I don't have the error anymore

  • Community Member Profile Picture
    on at

    I manage to make it work! Thank you very much. Right I just added the uilanguageid to the email title for testing and it does send the right code for each language.

    This is my final code.

    Entity userSettings = localContext.OrganizationService.RetrieveMultiple(
           new QueryExpression("usersettings")
           {
              ColumnSet = new ColumnSet("uilanguageid"),
              Criteria = new FilterExpression
              {
                    Conditions =
                    {
                    new ConditionExpression("systemuserid", ConditionOperator.Equal, request.ac_Requester.Id)
                    }
              }
           }).Entities.FirstOrDefault();
           if (userSettings != null && userSettings.Contains("uilanguageid"))
           {
              if (userSettings != null && userSettings.Contains("uilanguageid"))
              {
                 languageCode = int.Parse(userSettings["uilanguageid"].ToString());
              }
            }
    


  • Aiden Kaskela Profile Picture
    19,696 on at

    That's awesome Philippe! If you wouldn't mind, could you do me a favor and mark any helpful answers as Verified?

    Let me know if you have any other questions, I'll be happy to help.

    Thanks,

     Aiden

  • Community Member Profile Picture
    on at

    Done! Have a good day.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans