During those past few days, I have been working on the Sitecore SPEAK. I wanted to build a UI using the Sitecore SPEAK Framework for a module that makes use of Powershell. So, in this post, I will explain how you can integrate Sitecore Powershell with SPEAK.
At first, it seems to be an easy task. But it wasn’t. To be able to have the Powershell on a SPEAK UI, I have used the below steps:
Let’s say you have a Dashboard where you have a button on it.
When you click on the button Create new site, you want to have an input dialog to appear which is obtained from the Powershell as shown below:
Note that you will require Sitecore Rocks plugin on the Visual Studio, which I think most of you already have and I am making use of the SPEAK 2.0.
The diagram below shows an overview of the flow which will be explained in the post.
On your dashboard, you will require to insert a DialogWindow and Frame rendering. The dialog window should contains the frame rendering. For example, if my dialog window is named SiteGeneratorWindow, the frame placeholder should be SiteGeneratorWindow.Content. For this blog post, the
id of the frame rendering is `SiteGeneratorFrame`.
When the function is executed, it performs an ajax call to the C# code. The function snippet is provided below:
At line 13, I need to set the source url to empty because I have seen that if I close the window, it may happened that it does not open again unless I clear the browser cache. Since this is a MVC application, you will need to specify the url in your route config.
Now, in the controller, I have implemented a method which needs to build a url. The url is the powershell runner along with the Id of the script found in the Powershell Scripts Library. This is required in order to be able to execute the powershell script.