Sitecore SPEAK with Powershell – Part II

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:

runner.png

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.

dialog

Dialog window with Powershell Runner

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.

Basic.png

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:

ScriptSession.png

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.

Powershell Scripts

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 -ContextItem.

In terms of code, you can read my previous post here where you will find how to write the JavaScript functions and how to setup the different renderings. Just to note that, the Dialog Window visibility should be set to false. You can do this in either Sitecore Rocks from the Properties Window or via JavaScript in the initialize function.

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.

ezgif.com-crop

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s