edit item via button on ribbon using powershell with prompt
There may be instances where properties are frequently updated on a node that is nested within the Content structure. To make the experience easier for less frequent editors, you can allow these properties to be updated via a dialog that is trigger by a button in the ribbon.
Steps are as follows:
- Create a new PS Script and store in the PS Script library, usually located at
/sitecore/system/Modules/PowerShell/Script Library/
- Write your script (an example can be found in the code block below)
- Note the ItemId of the newly created script.
- Swap to the Core DB
- Add a new
Chunk
in the relevant section below/sitecore/content/Applications/Content Editor/Ribbons/Chunks/
- Populate the Header, Icon, Tooltip, ID fields as required, populate the
Click
field withitem:executescript(id=$Target,script={ItemIdOfPsScript},scriptDb=master)
tip
You may want to restrict access to this button for certain users/roles. To do this Assign Security Rights for the newly created Chunk
.
As an example you may want to deny Read on the Item for sitecore\Sitecore Client Users
so that only Admins can see the button.
$systemSettings = Get-Item -Path "master:path-to-item" -Language "en-GB"
$dialogParams = @{
Title = "Title for what you are doing"
OkButtonName = "Update and publish"
CancelButtonName = "Cancel"
Parameters = @(
@{
Name = "propertyOne"
Title = "Property One"
Value = $systemSettings.Fields["PropertyOne"].Value
}
@{
Name ="propertyTwo"
Title = "Property Two"
Value = $systemSettings.Fields["PropertyTwo"].Value
}
)
}
$dialogResult = Read-Variable @dialogParams
if ($dialogResult -ne "ok")
{
Exit
}
$systemSettings.Editing.BeginEdit();
$systemSettings.Fields["PropertyOne"].Value = $propertyOne;
$systemSettings.Fields["PropertyTwo"].Value = $propertyTwo;
$systemSettings.Editing.EndEdit();
Publish-Item -Id $systemSettings.ID -PublishMode Full -Language '*' -RepublishAll -Verbose