knowledge articles UI action

Vinya Jakkula
Tera Contributor

Hi Team, can anyone help me please 

I have created a custom UI action on knowledge table. I required to give the kb number in URL path. But here always picking the expired article.

function onClick(g_form) {
    var sys_id = g_form.getUniqueValue();
    var instance = "https://" + parent.location.hostname + '/now/workspace/hr/record/kb_knowledge';
    var knowLink = instance + '/' + sys_id;

    parent.navigator.clipboard.writeText(knowLink).then(function() {
        /* clipboard successfully set */
        alert("Copied to clipboard.");
    }, function() {
        /* clipboard write failed */
    });

}
8 REPLIES 8

@Vinya Jakkula 

that's what I mentioned you can use GlideRecord and get article which is not retired and pass the sysId

this link will require sysId and not number

var knowLink = instance + "/now/sow/kb_view/kb_knowledge/" + number; // Construct the URL

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar I don't want sys I'd I required kb number. Example:

1000011650.jpg

harshita malhot
Tera Contributor

Hi @Vinya Jakkula ,

In your code, you are using var knowLink = instance + '/' + sys_id; which takes the sys_id of the knowledge article that can result in pulling out the expired version of the article. If you wish take only the  latest version of the article then you can point to the KB number in the URL instead of the sys_id.

Hi @harshita malhot 

I have done already but knowledge record not found error getting:

function CopyKnowWorkspace() {
    var number = g_form.getValue('number');
    var instance = "https://" + parent.location.hostname; // Get the instance hostname
    var knowLink = instance + "/now/sow/kb_view/kb_knowledge/" + number; // Construct the URL

    if (number) {
        // Copy the link to clipboard
        copyToClipboard(knowLink);
        alert("Copied to clipboard: " + knowLink);
    } else {
        alert("Knowledge article number is not available. Unable to generate link.");
    }
}