SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom action in a ribbon, and I need to enable the button only if current user has permission to edit the item (Contribute role). The action is defined in a document library, the way it should work is that user selects (highlights) an item and if he has edit permission the button should be enabled (much like 'Edit item' built in button). Also keep in mind that items can have different permissions.

I have a PageComponent to tell the UI if command can be handled, but I can figure out how to check user permissions for an item in javascript.

This is in my PageComponent:

        canHandleCommand: function (commandId) {
            switch (commandId) {
                case 'Command1':
                    var ids = getSelectedIds(); // gets an array of selected ids

                    var selectionChanged = false;
                    if (ids.length != this.previousIds.length) {
                        selectionChanged = true;
                    } else {
                        for (var index in ids) {
                            if (ids[index] != this.previousIds[index]) {
                                selectionChanged = true;

                    if (selectionChanged) {
                        this.enabledStatusChecked = false;

                    this.previousIds = ids;

                    if (!this.enabledStatusChecked) {

                    return this.isEnabled;

            return false;
        checkIsEnabled: function (ids) {
            this.enabledStatusChecked = true;
            this.isEnabled = false;

            if (ids.length != 1) {

            var id = ids[0];

            var context = SP.ClientContext.get_current();
            var web = context.get_web();

            var list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());
            var item = list.getItemById(id);

            context.executeQueryAsync(Function.createDelegate(this, function () {
                var contentTypeId = item.get_item('ContentTypeId').toString();
                if (!contentTypeId.lastIndexOf(Constants.InternalNormContentTypeId, 0)) {
                    this.isEnabled = true;
                    // !! need to check permissions here !!
            }), Function.createDelegate(this, function () {

This code enables the button only if 1 item is selected and if it is of specified content type. Does anybody have any idea about how to check permission through javascript?

share|improve this question

CustomAction has Rights attribute which accepts the permission levels. SharePoint should take care of disabling it if user does not have permission that you set.

share|improve this answer
That doesn't work with the rest of the page component code. I also need to check the content type of selected item and count of selected items. Also, I'm not sure whether it would work on per item basis. – Necros Jul 20 '11 at 8:04
What if I want permissions for different object? How can I specify list for those permissions? (Eg. workflow that work on 2 lists, and want to check 2nd list permissions) – przemo_li Nov 27 '14 at 12:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.