The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Checkout an article via the Flow Designer

Anish Reghu
Kilo Sage
Kilo Sage

Dear experts,

 

What are the logics I should validate to Checkout an article from a Flow Designer?

My learnings are:

 

  1. We need the article number (Input for the Custom flow Action)
  2. We need to query the version (kb_version) table to find if there exists a 'Draft/Review' article for the knowledge article, then we should return the sys_id of that article via the custom action.
  3. Otherwise, if the Workflow State is Published, we should do a checkout using the following:
    new KBVersioning().checkout(gr, false);​
    which will return a kb_version record and we can get the sys_id of that record.

Ultimately, I want to update the knowledge article body. And I am following this method because unlike an incident record or others, the KB article cannot be updated straightforward.

(function execute(inputs, outputs) {
    var kbNumber = inputs.articleNumber;
    var gr = new GlideRecord('kb_knowledge');

    if (gr.get('number', kbNumber)) {
        var knowledgeId = gr.getUniqueValue();

        // Step 1: Look for an existing active (unpublished) version
        var versionGr = new GlideRecord('kb_version');
        versionGr.addQuery('knowledge', knowledgeId);
        versionGr.addQuery('workflow_state', 'NOT IN', 'published,outdated');
        versionGr.orderByDesc('version'); // get latest draft/review version
        versionGr.setLimit(1);
        versionGr.query();

        if (versionGr.next()) {
            // Found an existing draft or review version
            outputs.draft_sysid = versionGr.getUniqueValue();
        } else {
            // No active version exists, so checkout a new draft
            if (gr.workflow_state == 'published') {
                var draft = new KBVersioning().checkout(gr, false);
                if (draft) {
                    outputs.draft_sysid = draft.getUniqueValue();
                }
            } else {
                // Article isn't published and no active version found — handle as needed
                gs.addInfoMessage('Article is not published and no active version found.');
            }
        }
    } else {
        gs.addErrorMessage('KB article not found: ' + kbNumber);
    }
})(inputs, outputs);

//OUTPUT : The article body of the Published article is changed to 'KB article not found: undefined'.

Instead I want the Checkout to Checkout the Published article and return me it's sys_id.
(Or) if there exists a Draft version of the article, return that sys_id.

 

Did I miss something?

 

Regards,

Anish

3 REPLIES 3

Rafael Batistot
Kilo Patron

Hi @Anish Reghu 

 

Why are you using flow designer to handle articles when the standard flow is via workflow editor?

 

https://www.servicenow.com/docs/bundle/zurich-servicenow-platform/page/product/knowledge-management/...

Hi @Rafael Batistot,

 

Thanks, I am aware of the KB workflows.

But this is for a specific use case that I am seeking help for.

 

I am executing a skill in the flow designer, which outputs a JSON string.

 

I need to update the KB article, with the skill output, for which I need to Checkout first. (according to the Workflow)

Hence, this script is to perform the Checkout the KB article first.

 

Regards,

Anish

Hi @Anish Reghu 

also can you check below line is not valid query for kb_version table. I believe there is no such field in kb_version table.

 versionGr.addQuery('workflow_state', 'NOT IN', 'published,outdated');

  try below line

versionGr.addEncodedQuery('knowledge.workflow_stateNOT INpublished,outdated');