Thursday, May 16, 2013

This is very useful information to know by all SharePoint developers. Recently I have reviewed a code from one of the SharePoint developer who written good ECMAScript for loading list data. All is good except the logic to get the site relative url. He has written a function which is 10 lines of code to get the site relative url. But, the code will not work in all the scenarios. If you think, SharePoint site can be like /spsite or /sites/spsite or /sites/something/something etc.. So, please don't write your custom logic and know the OOB features available around you. Below are the global variables available in Javascript for SharePoint Developers.

L_Menu_BaseUrl: To read the current site relative url you are in. This will be very useful in almost all the code we work with SharePoint data through javascript.

Example: If you are writing code to generate anchor links dynamically to take users to lists, views and pages   then this is the most useful variable.

you can set the href like L_Menu_BaseUrl + "/lists/Tasks". This will results the path to the tasks list. No matter in which site you are in, it always take the user to the correct lists location.

L_Menu_SiteTheme: To get the name of the current site theme.

L_Menu_LCID: To get the current site LCID. It will be useful in knowing the language details of the site. To understand these ID number you must check the other post here.

_spUserId: To know the current login user ID. By using this variable we can query to SharePoint to get more details of the user like profile, email, name etc.. 

Categories: ,


Post a Comment