USING AZURE FUNCTIONS TO POST TO SLACK FROM MULTIPLE SOURCES – PART 2 (Cireson Portal)

Following up on last weeks post, this week we will look at using our Azure Function app to post work item information from a custom task in the Cireson Portal to Slack.

Now that we have our Azure Function app in place and we know it’s working, you will be surprised how simple this custom task is going to be. It really just takes a basic knowledge of javascript and the underlying viewmodel in the Cireson Portal.

For information on customizing the Cireson Portal you can take a look at http://support.cireson.com if you are an existing customer. I’m just going to give you a very brief explanation here.

Basically, when working with the portal you are going to do all your work in the CustomSpace folder. Specifically, most of what you will do can be done in the custom.js file in this folder. That is where we are going to be working today.

The first step is to setup a custom task using the following format:

2016-10-06_14-42-18

You can add multiple tasks, and change the first variable to ‘ServiceRequest‘ or ‘ChangeRequest‘ in order for the task to show up on those forms as well. In this case we will just focus on the Incident form.

The second variable is the name you want the task to show up as. With just this bit of code saved in the custom.js we now see this on the Incident form:

2016-10-06_14-44-37

Right now, if you were to click the link it would do absolutely nothing, as we have nothing in our code block… so let’s resolve that by adding the following code inside the codeblock:

2016-10-07_9-28-20

Now if we save and refresh our page, we can click the task and we should see the information above (nearly identical to our post from postman previously) show up in Slack like this:

2016-10-07_9-32-12

It worked, but you might have noticed an error in your browser developer tools though when you clicked the link. This has to do with CORS or the processes of passing a data request from one domain to another via the browser, it still worked so you can ignore this, but I don’t like errors so let’s see if we can fix it…

Open up your Azure portal and head over to your Azure Function app and select the ‘Function app settings‘:

2016-10-07_9-38-19

From there we can select ‘configure CORS‘:

2016-10-07_9-43-18

And then remove all of the existing sites and add a (*):

2016-10-07_9-46-53

Save your settings and wait just a minute or so and then run your custom task from the portal again and this time you should see a clean developer console. With that you are pretty much set! We are now grabbing work-item data and posting it into Slack. We can then expand this a bit if we desired just to make the experience a little better.

As a quick example we will add a loading mask while the function is posting and then remove the mask when it posts successfully. To do this simply update your postToSlack function like so:

2016-10-07_10-22-18

Now when you click the custom task you’ll see a waiting screen while the asynchronous function runs:

2016-10-07_10-29-55

And then the mask is removed when the function completes, successfully or with an error.

That’s really all there is to it! You can add and remove properties that will be displayed in the text and even format the posts different by simply using mrkdwn in your text fields.

Next week I’ll show you how to use powershell and a scheduled task to do the same thing but for all newly created Incidents inside SCSM!

 

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s