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

Ankur Bawiskar
Tera Patron
Tera Patron

@Vinya Jakkula 

try this

function onClick(g_form) {
    var sys_id = g_form.getUniqueValue();
    var instance = "https://" + parent.location.hostname + '/now/workspace/hr/record/kb_knowledge';
    
    // Create a GlideRecord to check the state of the knowledge article
    var gr = new GlideRecord('kb_knowledge');
    if (gr.get(sys_id)) {
        if (gr.getValue('workflow_state') !== 'retired') { // Check if the article is not expired
            var knowLink = instance + '/' + sys_id;

            parent.navigator.clipboard.writeText(knowLink).then(function() {
                /* clipboard successfully set */
                alert("Copied to clipboard.");
            }, function() {
                /* clipboard write failed */
            });
        } else {
            alert("The selected knowledge article is expired.");
        }
    } else {
        alert("Knowledge article not found.");
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar  i need KB number instead of sys id.but here in workspace not working.

@Vinya Jakkula 

what debugging did you perform?

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

  • @Ankur Bawiskar  I have written this script as I required kb number instead of sys I'd.but it is getting the knowledge record not found.
  • 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.");
        }
    }
  • 1000011648.png