- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎06-18-2018 03:56 AM
A few months back when I was wondering how can we use D3JS and found interesting article by @mitchellstutler.
Tried few examples and was quiet happy as now we knew how to use D3 in ServiceNow (not limited to ChartJS or HighCharts).
Yesterday I was going through the recent stuff posted by sentdx and he happened to be working on TensorFlow JS (for a change). And now I wanted to see put a simple TF.JS program on SN platform. So lets begin this:
TensorFlow.js
A JavaScript library for training and deploying ML models in the browser and on Node.js
Source : Wikipedia
TensorFlow is an open-source software library for dataflow programming across a range of tasks. It is a symbolic math library, and is also used for machine learning applications such as neural networks. It is used for both research and production at Google,often replacing its closed-source predecessor, DistBelief.
TensorFlow was developed by the Google Brain team for internal Google use. It was released under the Apache 2.0 open source license on November 9, 2015.
Add the dependency and run first widget(Yes As simple as that :P)
Lets first add a dependency library :
ServicePortal -> Dependency
URL is
https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.6

Now lets get the widget up and running 🙂
Lets move to the widget editor :
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.6"> </script>
<!-- Place your code in the script tag below. You can also use an external .js file -->
<script>
// Notice there is no 'import' statement. 'tf' is available on the index-page
// because of the script tag above.
// Define a model for linear regression.
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
// Prepare the model for training: Specify the loss and the optimizer.
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
// Generate some synthetic data for training.
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
// Train the model using the data.
model.fit(xs, ys, {epochs: 10}).then(() => {
// Use the model to do inference on a data point the model hasn't seen before:
// Open the browser devtools to see the output
model.predict(tf.tensor2d([5], [1, 1])).print();
});
</script>
Open the browser console to see the output :
Okay that prediction worked.
Basic usage but thought to share with you all :).
- 2,818 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Surendra,
Nice to see an article under tensorflow and servicenow widgets. Please let me know if you have any material or documents for the same. I am quite interested in bringing something new combining these two platforms.
Thanks, Akash

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Surendra,
Very good, thanks for sharing.
I am in the process of learning TensorFlow myself so very interested in any more experiment you have done to leverage TF with ServiceNow.
I also found a presentation but unfortunately don't have link to the demo:
https://www.slideshare.net/AshishKumar207/build-a-neural-network-for-itsm-with-tensorflow
Laurent
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Dear Laurent,
Well, I wanted to play with TF and do lightweight lifting, but somehow this project also became a backyard project and is delayed.
Thought of working on this:
To check the possibility of somehow saving trained models and reuse them. (So that user interaction is smooth if we want to introduce Prediction or Smart classification - Ad Hoc Request{interactive/systematic})
And btw got me involved in a project where a flask app was used for the Assignment group classification based on Description of the ticket and made this flask app talk to ServiceNow.
Hey if you have any ideas up your sleeves please let me know .. we can jam together .. 🙂
Regards
Surendra Raika
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Surendra,
good work. Really inspired me to work on it.
Could you kindly let me know if we can train our models using tensorflow in the server and call it in the browser.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Shariq,
I have been experimenting with TensorFlow and ServiceNow too.
In the example above, it uses TensoFlow.JS which allows you to use Javascript.
The data is actually coded in the Javascript and is some demo data. You can probably run a glide query to extract some data and then use it.
What I have been working on though is TensorFlow (not the JS variant).
It is available as a Docker container so you don't need to install it.
https://www.tensorflow.org/install/docker
It is also available on Google Colab:
https://colab.research.google.com/notebooks/welcome.ipynb
The main point though is before using TensorFlow, what do you want to achieve with it and what data do you have to support it.
So far I have played with ticket data using ticket duration and survey results to try and highlight correlation (i.e predict survey results based on MTTR). Preparing meaningful data in the right format (needs to be rescaled etc) is the most important point in my experience. Applying a regression or other TF algorithms to it is relatively straight forward.
I'm planning to write a series of articles on the topic based on my journey 🙂 but above are my thoughts so far.
Let me know what you have in mind and I'll see if I can help further.
Laurent
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Laurent,
Thank you for your response.
Can you kindly explain the lines " and is some demo data. ."-where is it stored (in servicenow or outside instance)
"You can probably run a glide query to extract some data and then use it."- Glidequery on which data?as a ml logic may have more than 1000 data (in form of text or image) to train on.
And can we not download the standalone build of tensorflow hosted locally instead of the docker version?
btw eagerly waiting for the article series . all the best with your works.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Shariq,
If you look at the code above, there is a line that says:
"// Generate some synthetic data for training.
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]); const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);"
That's basically creating a matrix with some dummy data in it, so it is not using data from ServiceNow.
That's why I said you would need to construct a glide query and then populate a matrix.
To your other question, yes you can absolutely download and install TensorFlow locally. I went the docker route but both are possible.
So the approach I have taken, is that I created a report in ServiceNow which produces incident data as well a survey results and export that as CSV. It can be then be queried using Pandas to extract the columns you are interested in.
In my case I am playing with incident duration and survey score to try and get some correlation (i.e the longer it takes to fix an incident, the lower the survey score is likely to be). That's an example I came up with to test tensorFlow but I am sure there are better ones 🙂
I'll try an post some screenshots soon (I have some data type issues I need to fix first! 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Laurent , this was a straight forward example of using TF in ServiceNow ... And I took a break from implementation of this idea..
Let me share one of the ideas I had :
We were using a python prediction program (basic classification using regression technique) to predict a possible Assignment group for any new ticket. And I thought of bringing that logic to the platform itself as we can use TF in JS now.
Problem : How to save the models 😛 .
Regards
Surendra
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Laurent/Surendra,
how to fetch/load model.json and weight.bin from two different URL?
I realized loading and saving methods of tensorflow models can be used here, but since servicenow stores files(attachments) in different sys_id, thus it may not be direct. I thus posted the above question in stackoverflow for a wider audience.
Requesting you to kindly have a look at it and let me know if you have any inputs on it.
Thanks,
Shariq