Based on my previous post on how to execute Powershell scripts when using Sitecore SPEAK Framework, the part 2 will consist on how to trigger a scripts which makes use of the “Powershell Runner”.
By default, when you execute a Powershell script from the Content Editor or the ISE, you will see the below runner:
But, when executing a script on SPEAK, it is a bit different. The method I am currently using is making use of a Dialog Window and a Frame on it. The Dialog Window visibility is set to false because the user interface being shown is not appropriate. In other words, the Powershell Runner does not look good on the Dialog Window.
Now, since I have set the visibility of the dialog to false, the issue which came up is if the script is a long process, for example, deletion of multiple items, the runner will not be shown and the user will be notify only at the end IF an alert box is used else, he/she will need to manually check if the process has been completed or not.
So, during this post, I will show you how to show the Powershell Runner as if it was not hidden. Let’s start. I will take the example of the deletion of items.
The first thing to do is to update the Powershell Script. Currently, the flow of the powershell script is from Sitecore, you perform a button click or call to the powershell script. The script is then executed and finally, provide the outcome.
What needs to be changed is to add a script which make use of the ScriptSession. So, in brief, the above diagram will change to the below one:
It is the script session which will perform the call to the Deletion Script. So, when you are triggering the button click, the dialog window will hide the Powershell Runner of the Script Session but since the Script Session is executing another script, it will make the Powershell Runner to appear.
So, I will have 2 scripts
Initializer – Trigger by the SPEAK UI which therefore executes the deletion.
Delete Item – Perform the removal of the items
Note that you can easily pass an item to the Delete Item script via the Initializer script using the attribute
A snippet of the JS code is shown below:
And that’s it. It should work like charmed. Below is an example of what I have achieved by using the above method.