- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2020 11:20 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 12:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 12:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 02:45 AM
Hi Ishita,
Thanks for the reply but it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 03:14 AM
I tried this code on my instance and it was working fine. I have not made any changes to the workflow.