SitecorePowerShell / Console

Sitecore PowerShell Extensions
https://doc.sitecorepowershell.com/
Other
114 stars 71 forks source link

Add ability to send deferred sheer messages and execute javascript to make it possible to e.g. refresh the content editor tree post script execution #1340

Closed AdamNaj closed 4 months ago

AdamNaj commented 4 months ago

Expected Behavior

When executing scripts operating on the currently selected item in Content Editor ore renaming it, it would be beneficial to be able to refresh the content tree or reload the current item.

This functionality is now added to two Cmdlets - Send-SheerMessage and Invoke-JavaScript: image

$item = $SitecoreContextItem
Send-SheerMessage -OnScriptEnd -Name "item:refresh" -Parameters @{id=&{$item.ID};language=&{$item.Language};version=&{$item.Version}}
Invoke-JavaScript -OnScriptEnd -Script "scForm.invoke('item:refresh(id=$($item.ID),language=$($item.Language),version=$($item.Version))')"

Send-SheerMessage -OnScriptEnd -Name "item:refreshchildren" -Parameters @{id=&{$item.Parent.ID}}
Invoke-JavaScript -OnScriptEnd -Script "scForm.invoke('item:refreshchildren(id=$($item.Parent.ID))')"

Send-SheerMessage -OnScriptEnd -Name "item:refreshchildren" -Parameters @{id=&{$item.ID};language=&{$item.Language};version=&{$item.Version}}
Invoke-JavaScript -OnScriptEnd -Script "scForm.invoke('item:refreshchildren(id=$($item.ID),language=$($item.Language),version=$($item.Version))')"

Close-Window

This can be used in the Content Editor Context menu and List View Actions.

Solves e.g. the problem described in #1316

AdamNaj commented 4 months ago

Done

michaellwest commented 4 months ago

What are the different uses cases for this?

AdamNaj commented 4 months ago

Mainly refreshing the tree in Content editor or reloading the item, but you can may also run a dialog after the script is finished. I initially thought about it when trying to write interactive script for workflow actions. But the main purpose is described in the issue title and shown in the image.