RSS Feed to Record
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 02:50 PM
I am trying to get an RSS feed to populate a table, however just cant seem to get it to work. Any help would be much appreciated!
The REST API has been set up and coming back with a code 200 and the connections there I just cant seem to get the records to import.
try {
var rssFeed = new sn_ws.RESTMessageV2('RSS Feed Import', 'GET');
var response = rssFeed.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
// Log the raw response for debugging
gs.info('RSS Feed XML Response: ' + responseBody);
var xml = new XMLDocument2();
xml.parseXML(responseBody);
if (!xml.isValid()) {
gs.error('Invalid XML response');
}
var items = xml.getNodeList('//item');
if (items.getLength() == 0) {
gs.error('No <item> nodes found in the RSS feed.');
}
for (var i = 0; i < items.getLength(); i++) {
var item = items.item(i);
var title = item.getNodeText('title') || '';
var link = item.getNodeText('link') || '';
var pubDate = item.getNodeText('pubDate') || '';
var description = item.getNodeText('description') || '';
gs.info('Item ' + (i+1) + ': ' + title + ' | ' + link);
var grCheck = new GlideRecord('u_rss_sky_tech');
grCheck.addQuery('u_url', link);
grCheck.query();
if (grCheck.next()) {
continue; // Skip if the URL already exists
}
var gr = new GlideRecord('u_rss_sky_tech');
gr.initialize();
gr.u_title = title;
gr.u_url = link;
gr.u_published = pubDate;
gr.u_article = description;
gr.insert();
}
} catch (error) {
gs.error('RSS Feed Import - Sky Tech: Error occurred - ' + error.message);
}
0 REPLIES 0