Share via


Implementing field level security for SharePoint List

Hi,

Sometimes we have to hide some of the columns of SharePoint list. We can implement this in two way

1)If we have to implement field level security at List level you can use following code which will be helpful,

<script>
ExecuteOrDelayUntilScriptLoaded(init,'sp.js');
var userGroups;
var currentUser;
function init(){
$('#field1_e4111e34-637f-4d8e-bd8a-d8666726b8e4_ChoiceRadioTable').closest('tr').hide(); // Select Field control id
CheckCurrentUserMembership();
}

function CheckCurrentUserMembership() {

var clientContext = new SP.ClientContext.get_current();
this.currentUser = clientContext.get_web().get_currentUser();
clientContext.load(this.currentUser);

userGroups = this.currentUser.get_groups();
clientContext.load(userGroups);
clientContext.executeQueryAsync(OnQuerySucceeded);
}

function OnQuerySucceeded()
{
var isMember = false;
var groupsEnumerator = userGroups.getEnumerator();
while (groupsEnumerator.moveNext()) {
var group= groupsEnumerator.get_current();
if(group.get_title() == "SharePoint Demo Members") {
isMember = true;
$('#field1_e4111e34-637f-4d8e-bd8a-d8666726b8e4_ChoiceRadioTable').closest('tr').show();
break;
}
}
}

function onQueryFailed(sender, args) {
}
</script>

2)Use SharePoint designer for this create Custom form there are also two options
   a) Create seperate input , display form for the users handling navigation  

   b) Use the same form with trick to check permssion. Please go through following blog.
http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=3