Skip to content
thesnowmonk.com

thesnowmonk.com

Servicenow Tips, Tricks and More.

Menu
  • Home
  • About
  • Contact Us
Menu

How to integrate ServiceNow with Application Insights

Posted on February 18, 2022April 1, 2022 by Arun

For those of you who are new to ‘Application Insights’, allow me to give you a quick intro! As the name suggests this nifty little tool helps you gain insight into your web application like user stats, error monitoring, etc. With just a few lines of code in your application, you can find out what users are doing with it, or help diagnose issues.

If you’re the voracious learner kind, you can read more about Application Insights from the official docs.

Now, let’s get to the interesting bit, how can you leverage all that monitoring goodness in your ServiceNow instance.

The Azure bit (not so much):

Assuming that you have your Azure application insights setup already (as we will not be covering that as part of this post). Head over to your Application Insights dashboard and copy over the instrumentation key. It should look something like this:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

The ServiceNow bit:

  • Create a UI Script
  • Create a self invoking function (yes! you can copy/paste the snippet),
(function() {
	var d = document,
	f = d.createTextNode('**Paste the SDK code here with the instrumentation key**'),
	g = d.createElement('script'),
	h = d.getElementByTagName('head')[0];
	g.type='text/javascript';
	g.appendChild(f);
	h.insertBefore(g, h.firstChild);
} )();
  • Head over to your Service Portal theme.
  • JS include the UI Script onto your theme.
  • Okay, all that’s great. Now how do I use this thing?!
  • Wherever you would like to place the app insight tracking api in the widget client controller, do so as follows,
var insightsObj = {};
var user = $scope.user.name + '(' + $scope.user.user_name + ')';
insightsObj = {
title: 'Demo Insights Click',
user: user
}
appInsights.trackEvent(
{
 name: "Demo Insights Event", 
 properties: insightsObj
}
);

And there you have it! Live metrics at your doorstep

image.png

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

About This Site

This site is developed and maintained by a ServiceNow developer just like you! An ardent snowhead who is giving you tried and tested tips, tricks and other snippets to get you ahead of the game.

©2025 thesnowmonk.com | Built using WordPress and Responsive Blogily theme by Superb