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 :
Dynamics 365 Community / Blogs / DevBeard.com / Using LINQPad to Quickly Sw...

Using LINQPad to Quickly Switch CRM UI Language

Henrik Gundersen Profile Picture Henrik Gundersen 978

Have LINQPad and the CRM 2011/2013 plugin? Do you need to jump between f.ex. Norwegian and English languages in the UI? Here is a code snippet you can paste in LINQPad that will switch for you. You will still need to refresh the browser.

// Change the following array to the list of LCIDs you wish to jump between
var languages = new []{1033,1044};

// Change the following string to the user you wish to switch language for
var systemuserFullname = "Abe Lincoln";

///////////////
var resultSet = from us in this.UserSettingsSet  
                    join u in this.SystemUserSet on us.SystemUserId.Value equals u.SystemUserId.Value
                    where u.FullName == systemuserFullname
                    select new{us.Id, attributes = us.Attributes.Where(i=>i.Key.Contains("lang"))};

foreach(var result in resultSet)  
{
    if(result.attributes.Where(i=>i.Key == "uilanguageid").Any())
    {
        var currentLanguageId = (int?)result.attributes.Where(i=>i.Key == "uilanguageid").First().Value;

        if(currentLanguageId != null)
        {
            var index = Array.IndexOf<int>(languages, currentLanguageId.Value);             
            var newIndex = (index+1) % languages.Length;            
            ("Switching to: "+languages[newIndex]).Dump();

            var update = new Entity("usersettings");
            update.Id = resultSet.First().Id;
            update.Attributes.Add("uilanguageid", languages[newIndex]);
            update.Attributes.Add("helplanguageid", languages[newIndex]);
            this.OrgServiceWrapper.Update(update);
        }
    }
}

This was originally posted here.

Comments

*This post is locked for comments