- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 11:20 AM
Folks, we are having an issue with our knowledge articles that contain external links. They are failing when the link is accessed by our technicians but open without issue from the portal side. It was suggested we should ensure all links have the target = '_blank' in the URL (which is defaulting to a new, external window), which we are doing and which works. The default behavior in our instance is that this tag is added automatically when creating a new URL using the link button in the editor or when the URL is typed into the field in the article. However, if the URL is pasted into the article, it does not insert the target tag, and the link will not resolve with a message "connection refused."
My question is, is an SSO issue? Does anyone else have this issue and; if so, what are you doing about it?
Thanks for your feedback,
Adam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 02:57 AM
You can use the following code to add target="_blank" to the content but updating the same back to article record will not work, because the HTML tags will be stripped before updating the record.
var gr = new GlideRecord("kb_knowledge");
gr.addEncodedQuery('textLIKE</a>^textNOT LIKEtarget="_blank"');
gr.setLimit(2);
gr.query();
while(gr.next()){
var htmlContent = gr.getValue("text");
var updatedHtmlContent = addTargetBlankToAnchorTags(htmlContent);
gs.print(updatedHtmlContent)
}
function addTargetBlankToAnchorTags(htmlContent) {
var regExp = /<a href="([^"]+?)"([^>]*)>/g;
htmlContent = htmlContent.replace(regExp, function(match, href, attributes) {
if (!attributes.includes('target="_blank"')) {
attributes += ' target="_blank"';
}
return '<a href="' + href + '"' + attributes + '></a>';
});
return htmlContent;
}
Please mark my answer helpful and accept as solution if it helped
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 06:39 AM
@AnveshKumar M , this is definitely helpful. I wasn't aware of "Glide" scripting, so I had pulled the data out of ServiceNow and extracted the bad links using Python. What I was hoping for was a solution to replace that bad links with corrected links. Is this something Glide can do and, if so, is that something you can share?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 02:57 AM
You can use the following code to add target="_blank" to the content but updating the same back to article record will not work, because the HTML tags will be stripped before updating the record.
var gr = new GlideRecord("kb_knowledge");
gr.addEncodedQuery('textLIKE</a>^textNOT LIKEtarget="_blank"');
gr.setLimit(2);
gr.query();
while(gr.next()){
var htmlContent = gr.getValue("text");
var updatedHtmlContent = addTargetBlankToAnchorTags(htmlContent);
gs.print(updatedHtmlContent)
}
function addTargetBlankToAnchorTags(htmlContent) {
var regExp = /<a href="([^"]+?)"([^>]*)>/g;
htmlContent = htmlContent.replace(regExp, function(match, href, attributes) {
if (!attributes.includes('target="_blank"')) {
attributes += ' target="_blank"';
}
return '<a href="' + href + '"' + attributes + '></a>';
});
return htmlContent;
}
Please mark my answer helpful and accept as solution if it helped
Anvesh