Sitecore SPEAK with Powershell – PART I

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.

Dashboard

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:

dialog.PNG

Implementation

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.

Untitled Diagram

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

Now, you need to add an `​onclick`​ event on the button. For me, I make use of the following: `javascript:app.triggerSiteCreator()`

event

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.

I need to set the Site Context to shell and then build the url. Once the url is built, I returned it to the JavaScript function. When the JS function receives the value, it needs to update the Frame rendering source url with that value.

ezgif.com-crop.gif

Advertisements

One thought on “Sitecore SPEAK with Powershell – PART I

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