I have a custom Button in the content Editor (Share), basically it just runs a PSE Script that moves final layout to shared layout. Only a specific role can see the button. Now my problem is, that the button is enabled even if the user has no write access to the item, and therefore he can run the script. For the save button etc. it seems to work. Does anyone know what kind of logic determines if the button is enabled or disabled?

How can I disable the button if I click on an Item without write Access?



2 Answers 2


For "normal" buttons not calling SPE script, this is straight forward. In your definition of click event, you hook command. For example for Display Name button, Click command is item:setdisplayname and it's defined like this:

   <command name="item:setdisplayname" type="Sitecore.Shell.Framework.Commands.SetDisplayName,Sitecore.Kernel" />

So basically this code is called:

enter image description here

Mind the QueryState method and how it's setting CommandState.Disabled status when Length of context items doesn't equal 1 (in other words, you do not have write permissions for that context item).

To solve your problem, you can implement something similar logic in your PS script so you won't run the script at the end when same conditions are met. It won't disable the button but at least it won't run the script when user doesn't have proper permissions.

  • Thank you for that clear explanation Peter. My Command is indeed just the trigger of the script: item:executescript(id=$ItemID,script={094BCEF9-26F5-4D1E-B518-E28ED7CF364B},scriptDb=master)
    – Bgl86
    Commented Mar 31, 2021 at 12:08
  • My pleasure @Bgl86 Commented Mar 31, 2021 at 12:11

When working with SPE you can use the rules fields (Show/Enable) to manage the state of the buttons. I use these at work all the time and work reliably.

As you can see in the following figure, the Elevated Unlock feature included with SPE makes use of the rules fields.

Elevated Unlock

The documentation in the SPE book outlines in which scenarios the Show Rule and Enable Rule are used. You can apply the rules at the script and script library levels, depending on your usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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