Checkout an article via the Flow Designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Dear experts,
What are the logics I should validate to Checkout an article from a Flow Designer?
My learnings are:
- We need the article number (Input for the Custom flow Action)
- 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.
- Otherwise, if the Workflow State is Published, we should do a checkout using the following:
which will return a kb_version record and we can get the sys_id of that record.new KBVersioning().checkout(gr, false);
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Anish Reghu
Why are you using flow designer to handle articles when the standard flow is via workflow editor?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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');