SharePoint page redirect If the current user belong to a specific group via JQuery SPServices

I have a web application ” http://epm/ ” with a site collection PWA,I only need If the current user belongs to a specific SharePoint group go directly to “http://epm/pwa/” when he tries to browse the root URL “http://epm/”

Steps:

  • Download Jquery from here > Upload it to Style Library.
  • Download SpServices from here > Upload it to Style Library.
  • Open the web application home page ” http://epm/ “.
  • Edit page > Add web Part > below Media & Content  > Script Editor Web Part or Content Editor Web Part.add script editor
  • Edit Script.
  • Paste the following code by replacing your URL.
/Style%20Library/js/jquery-1.7.1.min.js
/Style%20Library/js/jquery.SPServices.min.js
<script language="javascript" type="text/javascript">
$(document).ready(function() {
 $().SPServices({
 operation: "GetGroupCollectionFromUser",
 userLoginName: $().SPServices.SPGetCurrentUser(),
 async: false,
 completefunc: function(xData, Status) {
 if($(xData.responseXML).find("Group[Name='YourGroupName']").length == 1)
 {
window.location.href = "http://epm/pwa"; //redirect
 }
 }
 });
});

The above solution is simple and meets the purpose for a specific page.but What if the user accesses a subpage within the root web application beyond Homepage. Ex: http://epm/news.aspx.

In this case,you should add the above javascript code to a custom master page that only specified to the root web application.

Enjoy 🙂

Advertisements

4 thoughts on “SharePoint page redirect If the current user belong to a specific group via JQuery SPServices

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s