For checking if a user has permissions to edit an item and showing basing on this check an "Edit" button in the Display form's Command Bar, you can add this Function Code below in Visible Expression of the "Edit" button:
var isSubListForm = [[@Form.IsSubListForm]];
var listId = [[@Form.ListId]];
if (isSubListForm) {
return false;
} else {
return new Promise(function (resolve) {
var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getById(listId);
ctx.load(list, 'EffectiveBasePermissions');
ctx.executeQueryAsync(function () {
var canEdit = list.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems);
resolve(canEdit);
}, function (sender, args) {
console.error('Cannot check user permissions. Request failed ' + args.get_message() + '\n' + args.get_stackTrace());
resolve(false);
});
});
}
Comments
0 comments
Please sign in to leave a comment.