web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Community Member Profile Picture
    on at
    RE: Send email depending on user language

    HI Aiden,

    From where are you getting systemUserId in ( new ConditionExpression("systemuserid", ConditionOperator.Equal, systemUserId)). I am getting an error here

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Send email depending on user language

    refer below link

    aspsolutionkirit.blogspot.in/.../how-to-change-user-language-in-dynamic.html

  • Community Member Profile Picture
    on at
    RE: Send email depending on user language

    Done! Have a good day.

  • Aiden Kaskela Profile Picture
    19,696 on at
    RE: Send email depending on user language

    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
    RE: Send email depending on user language

    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());
              }
            }
    


  • Community Member Profile Picture
    on at
    RE: Send email depending on user language

    Never mind I don't have the error anymore

  • Community Member Profile Picture
    on at
    RE: Send email depending on user language

    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

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at
    RE: Send email depending on user language

    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
    RE: Send email depending on user language

    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);


  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at
    RE: Send email depending on user language

    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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans