The CreatorCon Call for Content is officially open! Get started here.

How to display KB Article name as display name instead of hyper link in catalog task?

Sujitha2
Mega Guru

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?

1 ACCEPTED SOLUTION

Sujitha2
Mega Guru

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); 
    }
}

View solution in original post

1 REPLY 1

Sujitha2
Mega Guru

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); 
    }
}