Modify User Regional Setting using SharePoint JSCOM

  • Posted by: Softree Technology

This article will help you to change the user regional setting based on supported ui languages presents on SharePoint online site.

[code lang=”c”]
<a href=”http://blog.softreeconsulting.com/wp-content/uploads/2017/01/userregionsetting.png”><img class=”aligncenter size-full wp-image-669″ src=”http://blog.softreeconsulting.com/wp-content/uploads/2017/01/userregionsetting.png” alt=”userregionsetting” width=”1018″ height=”348″ /></a>
SP.SOD.executeFunc(“sp.js”, “SP.ClientContext”, function () {
SP.SOD.registerSod(“sp.userprofiles.js”, SP.Utilities.Utility.getLayoutsPageUrl(“sp.userprofiles.js”));
SP.SOD.executeFunc(“sp.userprofiles.js”, “SP.UserProfiles.PeopleManager”, ManageUserRegionSetting);
});

function ManageUserRegionSetting() {
var oContext = SP.ClientContext.get_current();
var web = oContext.get_web();
var peopleManager = new SP.UserProfiles.PeopleManager(oContext);
userProfileProperties = peopleManager.getMyProperties();

oContext.load(userProfileProperties);
oContext.executeQueryAsync(function () {

try {
var currentUserAccountName = userProfileProperties.get_accountName();

var currentUserLcid = userProfileProperties.get_userProfileProperties()[‘SPS-Locale’];

var newLcid = “1036”; //Enter the lcid you want to set

if (currentUserLcid != newLcid) {

peopleManager.setSingleValueProfileProperty(currentUserAccountName, “SPS-Locale”, currentLcid);

oContext.executeQueryAsync(function () {
console.log(“Succesfully modified user region setting.”);
},
function (sender, args) {
//On Error
console.log(args.get_message());
});
}
} catch (e) {
//On Error
console.log(e.message);
}
}, function (sender, args) {
//On Error
console.log(args.get_message());
});
}

[/code]

This solution is brought to you by our SharePoint professionals…

Softree Consulting employs SharePoint consultants, We are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants have the right bent of mind to understand and execute customer requirements. Be it web part development, migrating from SharePoint 2010 to SharePoint 2013, Office 365 or something else in SharePoint, we strive to deliver the best

With more than 10 years of industry experience, these professionals have the best resources to deliver optimum results. They have been satisfying customers with some of the best SharePoint Strategies.

Author: Softree Technology

Leave a Reply