How to update preferred language (MUILanguages) in SharePoint Online using Power Automate

This is pretty much something that I have not found in a direct way on internet so I thought I must write about it and make someone else's life easier someday.

Scenario: 
I have scenario where my customer has SharePoint Online portal with multilingual support and some custom developed web parts. During the development phase, the tenant was different and I was able to redirect user to MyAccount so he can change the preferred language,  but this setting was not available on customer's tenant. The reason was, we had Azure AD profiles while customer has synced them from local AD so this setting was not available.

I recommend you to check out my this post about the language switch issue that I faced.

Problem: 
Since the manually preferred language change option was not available, we need to find another way where user can switch to any other language. In my case it was switch to Arabic from English.

Solution Overview:
Since the preferred way to make the language switch should be less effort for the end user, instead of letting the user do the manual work, I checked that there is another way to update the property "MUILanguages" in user profiles of SharePoint. Thanks to my colleague Mr. Gulzar Hassan for guiding me to right direction for its implementation.

There are two ways to change MUI in SharePoint Online for users.

Method 1:

Make a rest API call to SharePoint and update the properties. I have used PNP JS in my project so here is how I used to make call to SharePoint Online to update the "MUILanguages" property. This should work with other frameworks as well.

    private SetPreferedLanguage() {
        sp.web.siteUserInfoList.items
            .getById(11)
            .update({
                'MUILanguages': 'ar-SA'
            })
    }

Here I have created the function SetPreferedLanguage and called on my button click where as the key "MUILanguages" is set to my preferred language 'ar-SA' which is key for Arabic and (11) is the ID of the user for whom I want to change the language.

This method worked perfectly until the CHALLANGE has come.

The problem with this approach is, this need more than Read permissions on SharePoint site to change its profile property (I believe site owner permissions are required) which for sure I cannot give to all users. Also, in client side scripting language like React or Angular, you cannot run any task with elevated privilege neither you can implement impersonation through code. So what is the Solution?  Here comes the Method 2 which actually worked fine for this problem, its using Power Automate.

Method 2:
Microsoft has this wonderful platform that can serve you in this situation very well. To overcome the challenge, I have created a Power Automate flow which can take few parameters and do the necessary changes. The beauty of Power Automate is that it runs under the context of the service account which is used for making connection with the technology, in our case, SharePoint Online.

So, I have created the flow with some tweaking headers which updated the "MUILanguages" key for the user profiles. Here is the snapshot of the flow request.


Method: POST

URI: _api/web/siteuserinfolist/items(11)

Headers: 
{
  "accept": "application/json",
  "content-type": "application/json;odata=verbose",
  "If-Match": "*",
  "x-http-method": "MERGE"
}

Body:
{
  "__metadata": {
    "type": "SP.Data.UserInfoItem"
  },
  "MUILanguages": "ar-SA"
}

Here I am putting the User ID in items(11) as static but you can pass the User ID and the "MUILanguages" values dynamically and play around with the flow.

Hope this will help someone.

Happy SharePointing...! ðŸ˜Š

#MUILanguages

Comments

Popular Posts

GREYCstoration Oil Paint plugin for Photoshop

Service Bus Gateway service stuck at Starting

PowerApps SubmitForm not clearing People Picker value

Apple iPhone sending SMS automatically 00447786205094

SharePoint online hub navigation not updating for other users