In this blog, we are going to learn how to check the permission of the user on the list. Some times we need to show and hide several things as per the permission assigned to the user. SharePoint has different permission levels.
We are using the function of "sp.js", to use function of sp.js we need to include the sp.js file.
In this example, we are checking for the delete permission.
For more information go through this https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/
Happy coding..
We are using the function of "sp.js", to use function of sp.js we need to include the sp.js file.
In this example, we are checking for the delete permission.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { checkPermssion();
});
function checkPermssion(){
var web,clientContext,currentUser,oList;
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
currentUser = web.get_currentUser();
oList = web.get_lists().getByTitle(' List Title');
clientContext.load(oList,'EffectiveBasePermissions');
clientContext.load(currentUser);
clientContext.load(web);
clientContext.executeQueryAsync(function(){
if (oList.get_effectiveBasePermissions().has(SP.PermissionKind.deleteListItems))
{
console.log("user has delete permission");
}
else
{
console.log("user doesn't have edit permission");
}
},
function(sender, args){
console.log('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
});
}
For more information go through this https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/
Happy coding..
Comments
Post a Comment