Thursday 6 August 2015

Modify Site Regional and Language settings with JSOM and JavaScript

Recently, the ability to modify the Regional and Language settings of a site has been added to the client APIs in SharePoint 2013 and SharePoint Online. While the support for SharePoint 2013 was added in the December 2014 CU (as announced by Vesa here), the support for SharePoint Online has been a more recent addition.

There are some really nice code examples for the CSOM Regional and Language APIs in the Office Dev PnP Library:
https://github.com/OfficeDev/PnP/tree/master/Samples/Core.Settings.LocaleAndLanguage

But, I could not find JSOM code example of these APIs. So I am listing down some of the most frequently used Regional and Language functions here.

1) Add a Supported UI Language:



2) Remove a Supported UI Language:



3) Disable Multi Lingual and Remove all UI Languages:



4) Get Regional Settings:


A full list of all the regional settings properties is available here:
https://msdn.microsoft.com/EN-US/library/office/jj244880.aspx



5) Set Regional Settings:




6) Set Time Zone of a site:


This one was a bit tricky but I finally got there in the end. You will need to know the ID of the Time Zone you want to set in the site. A full list of SharePoint TimeZone IDs is here:
https://msdn.microsoft.com/library/microsoft.sharepoint.spregionalsettings.timezones.aspx



Hope this helps!

4 comments:

johnliu.net said...

This is fun! :-)

I've been looking at the region's timezone:
https://msdn.microsoft.com/en-us/library/office/jj245652.aspx

(no proper information on msnd makes me sad).


Pulling it out of REST on my tenant:

{
"Id": 76,
"Description" : "(UTC+10:00) Canberra, Melbourne, Sydney",
"Information" : {
"Bias": -600,
"DaylightBias": -60,
"StandardBias": 0
}
}

I recall a year ago I had only a Timezone string and had to fiddle with the +10:00 - this is somewhat better.

Vardhaman Deshpande said...

Yeah setting the timezone is a bit non intuitive.

What would have been better is something like regionalSettings.set_timeZone(timeZoneID) Or even if you could create a new SP.TimeZone object yourself and pass it to set_timeZone().

In both those ways, you don't have to make an extra call to get the TimeZone object first before setting it.

Sanjay said...

Hi,

Is it possible to get the Regional Settings of currently logged in user - not the web or site ??
I need to fetch the timezone offset for the logged in user (using client side - no server side) including the Day time savings. Kind of how Sharepoint renders.
When the newsfeed webpart is added, SharePoint injects _spRegionalSettings object on the page (viewsource), like _spPageContextInfo. I haven't found a way to get that object otherwise so far.

Thanks
Sanjay

Vardhaman Deshpande said...

Hi Sanjay,

You can use the "SPS-TimeZone" user profile property to get the timezone of a user.