Kb article ui action current data

pferreri
Tera Contributor

Hi everyone, I have a UI action that posts a kb article. What I have to do is:
Before publishing the article, ask if the user who clicks the UI action belongs to the assigned ownership group; if so, please post the article. Otherwise I have to call a flow and send an approval to every user that is in this ownership group.
If they don't respond to the approval or deny it, you should keep it as before. If they approve the approval, you should activate the publishing function.

The UI action is true active client. and this is the ui action script. is an OOB script
What I dont know how to do is send the current kb acticle data to and script include or busines rule and manage it there. 
Maybe we can find a solution. Thank u all

function onPublishActionClicked() {
    if (g_form.getTableName() == "kb_knowledge_block")
        gsftSubmit(null, g_form.getFormElement(), 'publish_knowledge');
    else {
        var checkGuestAccess = new GlideAjax("KBAjax");
        checkGuestAccess.addParam("sysparm_type""checkGuestUserHasAccess");
        checkGuestAccess.addParam("sysparm_id", g_form.getUniqueValue());
        checkGuestAccess.getXML(function(response) {
            var answer = '';
            if (response && response.responseXML && response.responseXML.documentElement)
                answer = response.responseXML.documentElement.getAttribute("answer") + '' == 'true' ? true : false;
            if (answer)
                renderModal();
            else
                gsftSubmit(null, g_form.getFormElement(), 'publish_knowledge');
        });

    }
}

function renderModal() {
    var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
    dialog = new dialogClass('confirm_publish');
    dialog.setTitle('Confirmation');
    dialog.setWidth(450);
    dialog.render();
}

if (typeof window == 'undefined') {
    publish();
}

function closeDialogAndPublish() {
    dialog.destroy();
    gsftSubmit(null, g_form.getFormElement(), 'publish_knowledge');
}

function publish() {
    new global.KnowledgeUIAction().publish(current); 
}
1 REPLY 1

SwarnadeepNandy
Mega Sage

Hello @pferreri,

First, you need to modify your UI action script to check the user’s membership in the ownership group. You can use the isMemberOf method of the GlideUser object to do this. For example:

 

function onPublishActionClicked() {
    // Get the current user object
    var user = gs.getUser();
    // Get the ownership group from the kb article record
    var ownershipGroup = g_form.getValue('ownership_group');
    // Check if the user belongs to the ownership group
    var isOwner = user.isMemberOf(ownershipGroup);
    // If the user is an owner, publish the article
    if (isOwner) {
        gsftSubmit(null, g_form.getFormElement(), 'publish_knowledge');
    }
    // Otherwise, call a flow and send an approval request
    else {
        // Call a flow using GlideFlow API
        var flow = new GlideFlow();
        // Pass the current kb article sys_id as an input variable
        var inputs = {'kb_article': g_form.getUniqueValue()};
        // Trigger the flow asynchronously and get the execution id
        var executionId = flow.startFlow('x_58872_needit_publish_kb_article', inputs, null, null);
        // Redirect the user to the flow execution page
        action.setRedirectURL('/$flow_execution.do?sys_id=' + executionId);
    }
}

 

 

Second, you need to create a flow that sends an approval request to the ownership group and publishes the article if approved. You can use the Flow Designer to create a flow with the following steps:

  • Start: Use a trigger type of Script and define an input variable named kb_article of type String.
  • Lookup Record: Use this action to get the kb article record by sys_id using the kb_article input variable.
  • Approval - User: Use this action to send an approval request to the ownership group of the kb article record. Store the output in a variable named approval.
  • Decision: Use this element to check the state of the approval output. If it is approved, go to the next step. If it is rejected or no response, end the flow.
  • Run Script: Use this action to run a script that publishes the kb article record. You can use the publish function from your UI action script.

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy