Sharepoint - Utils in JS

Functions to help to configurations in JS

  • Get user login info

   function getWebUserData() {
        var context = new SP.ClientContext.get_current();
        var web = context.get_web();
        var currentUser = web.get_currentUser();
var loginName = currentUser.get_loginName();
console.log(loginName);
    }
    ExecuteOrDelayUntilScriptLoaded(getWebUserData(), "sp.js");


  • Get if user has permissions to read

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {

// function to get if user as permission to edit list
function getCurrentUserPermission()

var web,clientContext,currentUser,oList,perMask;

clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
currentUser = web.get_currentUser(); 
oList = web.get_lists().getByTitle('InfoSuporte');
clientContext.load(oList,'EffectiveBasePermissions');
clientContext.load(currentUser);
clientContext.load(web);         

clientContext.executeQueryAsync(function(){
if (oList.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)){
console.log("user has edit permission");
}else{
 console.log("user doesn't have edit permission");

}, function(sender, args){
console.log('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
});
}
      });

Comments

Popular posts from this blog

Download file from input type file javascript

POST an array of objects with $.ajax to C# WebMethod

SQL Views - Variables