Instant publish of Knowledge article

Abhishek8
Tera Contributor

i  have a Knowledge base "VDB Knowledge" and i need when  we create a article in this KB,it should be published once the article is submitted

we set “Publish workflow” to “Knowledge – Instant Publish” expecting that newly created articles would not need an approval.

Nevertheless, an approval still is necessary.

I need once the artcle is submitted it should be in Published state

1 ACCEPTED SOLUTION

Ishita Shrivast
Kilo Guru

Hi Abhishek,

Try writing After Insert Business Rule on kb_knowledge table.The below code will publish the article as soon as it is submtted.

(function executeRule(current, previous /*null when async*/) {

// Add your code here


if(new KBKnowledge().canPublish(current)){

var prevValue = current.workflow_state + '';
if (current.kb_knowledge_base.kb_version == "3" && new KBWorkflow().startWorkflow(current, "workflow")) {
//If publish sub workflow is completed, workflow engine would have already done current.update()
if(current.workflow_state!='published')
current.update();
var knowledge = new GlideRecord("kb_knowledge");
if(knowledge.get(current.sys_id) && prevValue != knowledge.getValue("workflow_state")){
gs.addInfoMessage(new KBKnowledge().getStateMessage(knowledge.getValue("workflow_state")));
}
} else if (current.kb_knowledge_base.kb_version == "2") {
current.workflow_state = 'published';
current.update();
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
}
}

})(current, previous);

 

Please mark it as correct and helpful, if applicable.

Thanks and Regards,

Ishita Shrivastava.

View solution in original post

3 REPLIES 3

Ishita Shrivast
Kilo Guru

Hi Abhishek,

Try writing After Insert Business Rule on kb_knowledge table.The below code will publish the article as soon as it is submtted.

(function executeRule(current, previous /*null when async*/) {

// Add your code here


if(new KBKnowledge().canPublish(current)){

var prevValue = current.workflow_state + '';
if (current.kb_knowledge_base.kb_version == "3" && new KBWorkflow().startWorkflow(current, "workflow")) {
//If publish sub workflow is completed, workflow engine would have already done current.update()
if(current.workflow_state!='published')
current.update();
var knowledge = new GlideRecord("kb_knowledge");
if(knowledge.get(current.sys_id) && prevValue != knowledge.getValue("workflow_state")){
gs.addInfoMessage(new KBKnowledge().getStateMessage(knowledge.getValue("workflow_state")));
}
} else if (current.kb_knowledge_base.kb_version == "2") {
current.workflow_state = 'published';
current.update();
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
}
}

})(current, previous);

 

Please mark it as correct and helpful, if applicable.

Thanks and Regards,

Ishita Shrivastava.

Abhishek8
Tera Contributor

Hi Ishita,

Thanks for the reply but it is not working.

I tried this code on my instance and it was working fine. I have not made any changes to the workflow.