SharePoint On Premises 2013, 2016/ SharePoint Online JSOM - _spPageContextInfo Object In Different Environment / Versions

I was consulting on two projects --  one was SharePoint online (Office 365) and the other was SharePoint 2013 on premises. In SharePoint online we are very heavily using JSOM (JavaScript object model) so most of the time we need to use _spPageContextInfo object. But in SharePoint on premises we have the option to write server side code. In our project  when looking at  issues like performance and migration we were following the same approach in on premises project; i.e., using JSOM wherever possible.

In our SharePoint 2013 on premises project one of the requirements is to update the user name in one of our lists. We were updating the list using JSOM. So to get the current user log in name we used _spPageContextInfo.userLoginName. But we were not getting a user login name. I was really wondering why this was happening. I was very confident it would work since we have already used it intensively in our SharePoint online project.

After having thought for some time and debugging I realize that property userLoginName is not available in SharePoint 2013 on premises environment. Here is the need of comparisons.

So while working on different environment / different versions of SharePoint project or in migration projects we need to understand the properties available with different-different objects. Here I am showing the properties of _spPageContextInfo object, which is very heavily used nowadays in all kind of projects.

_spPageContextInfo object in SharePoint online / Office 365

Following are the figures showing all the properties available to _spPageContextInfo object in SharePoint online. In SharePoint online a maximum number of properties are available.

Fig 1 : _spPageContextInfo object properties in SharePoint online / Office 365

SharePoint

Fig 2 : _spPageContextInfo object properties in SharePoint online / Office 365

SharePoint

Fig 3 : _spPageContextInfo object properties in SharePoint online / Office 365

SharePoint

Fig 4 : _spPageContextInfo object properties in SharePoint online / Office 365

SharePoint

_spPageContextInfo object in SharePoint on premises 2013

Following are the figures showing all the properties available to _spPageContextInfo object in SharePoint on premises 2013.

Fig 1: _spPageContextInfo properties SharePoint on premises 2013

SharePoint

_spPageContextInfo object in SharePoint on premises 2016

Following are the figures showing all the properties available to _spPageContextInfo object in SharePoint on premises 2016.

Figure 1: _spPageContecxtInfo object properties in SharePoint on premises 2016

SharePoint

Just more information, from above figures, are the maximum number of properties available in Office 365. User related property userLoginName is added in SharePoint 2016 on premises. isSiteAdmin property is also an important one to know whether current user is Site Admin or not, added in SharePoint 2016 on premises.

Thanks!

Enjoy Reading!

As usual any comments / suggestions / feedback / questions always welcome :)