We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

UI Action to redirect to Knowledge Article form (without hardcoded url)

F_bio Santos
Kilo Sage

Hi everyone I have a requirement to make a UI Action that when clicked, it will redirect the user to the knowledge article form so that the user can create a new article, does anyone know's how to make this redirect dinamic ?

(without a hardcoded url)

1 ACCEPTED SOLUTION

Thanks,

That UI action you copied is specific to the 'Incident Management for Service Operations Workspace' scope, so if you've copied the code and are running it in a different scope (for example global) you'll end up with an error and the UI action failing.

 

Change

new SOWIncidentKnowledgeUtils().getNewKnowledgeArticleLink(current);

to

new global.IncidentKnowledgeUtils().getNewKnowledgeArticleLink(current);

View solution in original post

6 REPLIES 6

Kieran Anson
Kilo Patron

Depending on the plugins you've installed, there a few examples of directing a user to a knowledge article. 

For example, incident has 'Create Knowledge' which you could copy the logic of

Yeah I tried it but for some reason when I click the UI Action it redirects me to the UI Action form instead of redirecting me to the KB article

Share your code?

var issueLabel;
var resolutionLabel;

if (GlidePluginManager.isActive('com.snc.incident.knowledge')) {
    var targetURL = new SOWIncidentKnowledgeUtils().getNewKnowledgeArticleLink(current);
    if (targetURL) {
        action.setRedirectURL(targetURL);
    } else {
        gs.error("Could not get target URL for the Knowledge Article");
    }
} else {
    var sub = gs.getProperty('glide.knowman.submission.workflow');
    issueLabel = gs.getMessage("Issue");
    resolutionLabel = gs.getMessage("Resolution");
    if (sub == 'true')
        submitCandidate();
    else
        submitDirect();
}


function submitDirect() {
    var kb = new GlideRecord("kb_knowledge");
    kb.source = current.sys_id;
    kb.short_description = current.short_description;
    kb.sys_domain = current.sys_domain;
    kb.text = "<p><strong>" + issueLabel + "</strong> - " + current.description + "</p> <p><strong>" + resolutionLabel + "</strong> - " + current.close_notes + "</p>";
    kb.workflow_state = 'draft';
    kb.kb_knowledge_base = gs.getProperty("glide.knowman.task_kb", "dfc19531bf2021003f07e2c1ac0739ab");
    kb.insert();
}

function submitCandidate() {
    var gr = new GlideRecord('kb_submission');
    gr.parent = current.sys_id;
    gr.short_description = current.short_description;
    gr.sys_domain = current.sys_domain;
    gr.text = "<p><strong>" + issueLabel + "</strong> - " + current.description + "</p> <p><strong>" + resolutionLabel + "</strong> - " + current.close_notes + "</p>";
    if (gr.insert())
        gs.addInfoMessage(gs.getMessage('KB submission {0} was created and attached to the parent record {1}', [gr.getDisplayValue(), current.getDisplayValue()]));
}