
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 01:08 PM
I'm trying to create a function that will fetch the title of a web page given the URL.
My initial idea is to use the GlideHTTPRequest API using some sort of the following:
var url = 'https://www.servicenow.com/community/developer-articles/useful-string-methods/ta-p/2324172'; //Sample URL
var request = new GlideHTTPRequest(url);
var response = request.get();
gs.print(response.getBody());
However, I'm getting the HTML using this method.
I would appreciate any pointers to how I should approach this problem.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 11:29 AM - edited 11-02-2022 11:31 AM
Something like this seem to work but I am open for other suggestions:
var url = 'https://www.servicenow.com/community/developer-articles/useful-string-methods/ta-p/2324172'; //Sample URL
var request = new GlideHTTPRequest(url);
var response = request.get();
var html = response.getBody().toString();
var title = html.slice(html.indexOf('<title>')+7,html.indexOf('</title>'));
gs.print(title);
Note: If you use this code for pages in ServiceNow Community, you get "Bounce SSL" as title due to the redirect but it works for other web pages.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 11:29 AM - edited 11-02-2022 11:31 AM
Something like this seem to work but I am open for other suggestions:
var url = 'https://www.servicenow.com/community/developer-articles/useful-string-methods/ta-p/2324172'; //Sample URL
var request = new GlideHTTPRequest(url);
var response = request.get();
var html = response.getBody().toString();
var title = html.slice(html.indexOf('<title>')+7,html.indexOf('</title>'));
gs.print(title);
Note: If you use this code for pages in ServiceNow Community, you get "Bounce SSL" as title due to the redirect but it works for other web pages.