Introduction
This article introduces how to find or check a user group and filter Lookup column depending on group permission in SharePoint 2010 using spservices (jQuery).
Detailed Procedure
Step 1
Create a SharePoint site.
Step 2
Create a user group and add one user to the group, for example I have a user group Management and user Laxman vyavahare as shown bellow:
Step 3
Create two lists, namely Status and FilterStatus.
- The Status list contains the two column Title and Active (bool type) and add an item as in the following figure:
- Create a FilterStatus list that contains 2 columns, Title and the other is a lookup column on status list as in the Figure.
Step 4
Click on the Add new item link button and see the lookup column; here you can see the following 4 options:
- Approved
- Rejected
- Open
- Closed
But the Management user group has only access for Approval and Rejection so how I can hide (or by filter lookup column) open and close status from the management user group.
Solution
Step 5
Open the FilterStatus list in the Designer and add the following lines of code on NewForm.aspx or EditForm.aspx page under the <script> tag as below:
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
- <script type="text/javascript">
-
- $(document).ready(function () {
- alert('hi');
- $().SPServices({
- operation: "GetGroupCollectionFromUser",
- userLoginName: $().SPServices.SPGetCurrentUser(),
- async: false,
- completefunc: function (xData, Status) {
- if ($(xData.responseXML).find("Group[Name='Management']").length == 1)
- {
- alert("login inside of the Group user");
- $().SPServices.SPFilterDropdown({
- relationshipList: "Status",
- relationshipListColumn: "Title",
- columnName: "FilterStatus",
- CAMLQuery: "<Neq><FieldRef Name='Active' /><Value Type='Boolean'>Yes</Value></Neq>",
- completefunc: null,
- debug: false
- });
- }
- else {
- alert("login outside of the Group user");
- }
- }
- });
- });
- </script>
Step 6
Save both of the .aspx pages of the list and close the designer.
Step 7
Then open your FiltrStatus list and see the effect.
Now the Management group has access for Approval and Rejection.