
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 11:16 PM
Hi All,
I have a requirement, On SCTASK a new field is created 'KB Article' of Type - URL to display the KB Articles. I have a client script written based on the type of Task I need to add the KB Article URL. But I want it to display the name of the KB Article instead of the Hyper Link. On Click of the display name it should open the KB Article in a new tab.
Can someone please help me on how to achieve this in client script?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:48 AM
Solution:
Instead of Field type - "URL" I have used "HTML" and written the following code on the onLoad Client Script:
function onLoad() {
// Get the KB Article sys_id and name from the current SCTASK record
var kbArticleSysId = 'xxxx';
var kbArticleName = 'Example KB Article';
var shortDesc = g_form.getValue('short_description);
if (shortDesc == 'Test') {
// Create the URL for the KB Article record
var baseUrl = 'https://<your_instance_name>.service-now.com/nav_to.do?uri=';
var kbArticleUrl = baseUrl + 'kb_knowledge.do?sys_id=' + kbArticleSysId;
// Create the hyperlink HTML with the KB Article name as the link text
var hyperlinkHtml = '<a href="' + kbArticleUrl + '">' + kbArticleName + '" target="_blank"</a>';
// Set the generated HTML as the value of the HTML field on the form
g_form.setValue('html_field_name', hyperlinkHtml);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:48 AM
Solution:
Instead of Field type - "URL" I have used "HTML" and written the following code on the onLoad Client Script:
function onLoad() {
// Get the KB Article sys_id and name from the current SCTASK record
var kbArticleSysId = 'xxxx';
var kbArticleName = 'Example KB Article';
var shortDesc = g_form.getValue('short_description);
if (shortDesc == 'Test') {
// Create the URL for the KB Article record
var baseUrl = 'https://<your_instance_name>.service-now.com/nav_to.do?uri=';
var kbArticleUrl = baseUrl + 'kb_knowledge.do?sys_id=' + kbArticleSysId;
// Create the hyperlink HTML with the KB Article name as the link text
var hyperlinkHtml = '<a href="' + kbArticleUrl + '">' + kbArticleName + '" target="_blank"</a>';
// Set the generated HTML as the value of the HTML field on the form
g_form.setValue('html_field_name', hyperlinkHtml);
}
}