- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2017 11:42 AM
Hi Guys,
I want to be able to put an RSS feed on my Service Portal. Has anyone been successful in creating one and helping me out in creating one? Ideally, I want to pull the feed from Krebs at the top of the service portal homepage.
Thanks,
David R
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2017 06:59 AM
Hi David,
The reason the code you supplied doesn't work in Service Portal is because it uses an iframe that has a src path using plain http instead of https. It looks like you got the code from rssfeedwidget.com. But I don't believe they use https. So, even changing the url in the src attribute to use https more than likely won't get that to work either.
An alternative could be to use the RestMessageV2 and XMLDocument2 methods (and of course html and css to style it the way you want) to bring in the feed to your widget I have put together a very basic poc. It will bring in the Krebs on Security feed. It could also handle others too with a little adjustment. Most rss feeds are pretty much standard containing elements like channel, title, items, links etc.
Try putting this code within a widget and placing the widget on a page:
HTML:
<div class="panel panel-primary" ng-repeat="feed in c.data.feeds">
<div class="panel-heading">
<h4>${{{ feed.channel.title }}} - {{ feed.channel.description }}</h4>
</div>
<div>
<div class="list-group">
<div ng-repeat="item in feed.channel.items | limitTo: (offset - feed.channel.items.length) as filtered" class="list-group-item">
<a ng-href="{{item.link}}" target="_blank"><h3>{{ item.title }}</h3></a>
<h5>Author: {{ item['dc:creator'] }}</h5>
<div class="item-content">{{ item.description }}</div>
</div>
</div>
</div>
</div>
-------------------------------
CSS:
.item-content img {
width: 30%;
height: 30%;
display: block;
}
.feed-btn:first-of-type {
margin-left: 5px;
}
.feed-btn {
font-size: 9px;
}
----------------------
Server Script:
(function() {
try {
var r = new sn_ws.RESTMessageV2();
r.setHttpMethod('GET');
r.setEndpoint('https://krebsonsecurity.com/feed/');
var response = r.execute();
var responseBody = response.getBody();
data.httpStatus = response.getStatusCode();
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);
data.feeds = [];
var feed = {};
feed.channel = {};
var channel = xmlDoc.getNode('//channel');
var channelIter = channel.getChildNodeIterator();
var items = [];
while(channelIter.hasNext()){
var node = channelIter.next();
var nodeName = node.getNodeName();
var nodeContent = node.getTextContent();
if(nodeName != '#text' && nodeName != 'item')
feed.channel[nodeName] = nodeContent;
if(nodeName == 'item'){
var item = {};
var category = '';
var itemIter = node.getChildNodeIterator();
while(itemIter.hasNext()){
var itemNode = itemIter.next();
var itemName = itemNode.getNodeName();
var itemContent = itemNode.getTextContent();
if(itemName != '#text' && itemName != 'category')
item[itemName] = itemContent;
if(itemName == 'category'){
if(category.length > 0)
category += ','+itemContent;
else
category += itemContent;
}
}
item.categories = category.split(",");
items.push(item)
}
feed.channel.items = items;
}
data.feeds.push(feed);
}
catch(ex) {
var message = ex.getMessage();
}
})();
This should give you a good starting point.
I hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 07:41 AM
You're welcome David. I'm glad I could help.
To get "better" with ServiceNow depends on your definition of "better". One can really get to know, customize, and build custom applications without really knowing javascript. However, to really extend and make more powerful customizations then yes, learning javascript is definitely a good idea. Especially if building within the Service Portal side of ServiceNow. But a good place to start with ServiceNow would be to really know how it works. I.e. knowing how to customize it without using scripting.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 06:57 AM
Hi Chris, and first of all, thanks for this great widget, it seems to be working in general, but at least for me the items are sorted weirdly and not according to Date for example. I already tested to sort them on the HTML side with simply saying
<div ng-repeat="item in feed.channel.items | orderBy: 'pubDate' | limitTo: 10 as filtered" class="list-group-item">
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 08:03 AM
Hi Paavo,
I'm glad you find the widget useful.
I think there are a few options that can be done here.
1) If the value of pubDate is coming from a web service more than likely it's coming in a string format. Changing the value into a real date format may get the orderBy working properly
2) Or as you suggested sorting on the Server Script side: Take the end result array and run a .sort() method. More than likely the array contains objects, thus you'll have to create a function to pass into .sort() that will do the sorting. ie: .sort(sortOnDate(a,b)). Just keep in mind that if you still want to sort on pubDate and it is in string format, you'll still need to convert that into a date format.
Possible example:
data.reultsArray.sort(function(a,b){
return new Date(b.pubDate) - new Date(a.pubDate);
})

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2018 01:16 AM
Oh, wow, didn't expect that fast answer! Amazing. And since I'm totally newbie here, I was kinda hoping you could give me example in your original code so that I could steal it with pride. 😄
Any chance to get a bit more guidance here?
Regards,
Amateur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2018 06:28 AM
Sure thing.
Using the previous code if you look at where it's iterating and constructing the items you can simply convert the date into the correct format.
while(itemIter.hasNext()){
var itemNode = itemIter.next();
var itemName = itemNode.getNodeName();
var itemContent = itemNode.getTextContent();
if(itemName != '#text' && itemName != 'category')
item[itemName] = itemContent;
// Newly added conditiion and statement to convert string to date format
if(itemName == 'pubDate')
item[itemName] = new Date(itemContent);
if(itemName == 'category'){
if(category.length > 0)
category += ','+itemContent;
else
category += itemContent;
}
}
After doing that, orderBy should now work but it will be in ascending order (earlier dates first ie. oct, nov, dec). If you want the reverse of that then just add ":true" right after your orderBy setting in the mark up. For example orderBy: 'pubDate' : true