enablescript="javascript:commons.hasPermissionOnCurrentList('Ribbon_Documents_New_SelectButton', SP.PermissionKind.addListItems);" var _holder = {}; function getScopedVar(scopeId) { if (!_holder.hasOwnProperty(scopeId)) { _holder[scopeId] = {}; } return _holder[scopeId]; } ns.hasPermissionOnCurrentList = function (scopeId, reqPermission) { getScopedVar(scopeId).reqPermission = reqPermission; if (!getScopedVar(scopeId).hasOwnProperty("hasPermission")) { callServerUserHasPermission(scopeId); console.log("Result callServerUserHasPermission test for contextKey: " + scopeId + " is: " + getScopedVar(scopeId).hasPermission); return false; } // After RefreshCommandUI() called, set the result based on the returned value return getScopedVar(scopeId).hasPermission; }; function callServerUserHasPermission(contextKey) { getScopedVar(contextKey).hasPermission = false; var ctx = new SP.ClientContext.get_current(); var web = ctx.get_web(); //Get guid of currently selected list var currentListGUID = SP.ListOperation.Selection.getSelectedList(); getScopedVar(contextKey).list = web.get_lists().getById(currentListGUID) //_list = web.get_lists().getById(currentListGUID) ctx.load(getScopedVar(contextKey).list, 'EffectiveBasePermissions'); function onSucceeded() { var perms = getScopedVar(contextKey).list.get_effectiveBasePermissions(); getScopedVar(contextKey).hasPermission = perms.has(getScopedVar(contextKey).reqPermission); console.log("Result callServerUserHasPermission for contextKey: " + contextKey + " is: " + getScopedVar(contextKey).hasPermission); // Now let enabledScripts be re-evaluated RefreshCommandUI(); }; function onFailed(sender, args) { alert("doesUserHavePermission: " + args.get_message()); }; ctx.executeQueryAsync(onSucceeded, onFailed); };