Publish knowledge article on submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 12:29 AM
Hi, I want my knowledge article to go through the publish workflow when I press submit, and remove the publish button. My idea was to write a client script that calls a script include, but it's not working. Can anyone help please? 🙂
I also tried using a business rule also with no luck.
the scripts:
client:
function onSubmit() {
var ga = new GlideAjax('workflow_knowledge');
ga.addParam('sysparm_name', 'run_workflow');
ga.addParam('sysparm_recordTable', 'kb_knowledge');
ga.getXMLAnswer();
}
server: The function that runs on the Publish UI Action.
var workflow_knowledge = Class.create();
workflow_knowledge.prototype = Object.extendsObject(AbstractAjaxProcessor, {
run_workflow: function(){
if(new KBKnowledge().canPublish(current)){
var preValue = current.workflow_state + ' ';
if (current.kb_knowledge_base.kb_version == "3" && new KBWorkflow().startWorkflow(current, "workflow")) {
if (current.workflow_state != 'publish';{
current.update();
}
var knowledge = new GlideRecord("kb_knowledge");
if(knowledge.get(current.sys_id && preValue != 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")));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 02:17 AM
I found in the system log a warning that says:
Invalid query detected, please check logs for details[Unknown field knowledge_create.do?sysparmstack in table kb_knowledge]
Invalid query detected, please check logs for details[Unknown field stack.stack_status in table sn_cmp_order]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 01:42 AM
@Gunjan Kiratkar is right.
Notice that the business rule is on insert so it will only work the first time you save the article. I am saying so you don’t get confused while testing. Just and a check mark on update while testing.
Another thing to have in mind is that the rule is on the kb_knowledge table so if you are testing on an article on another table (known error for example) it won’t trigger.
If I helped you with your case, please click the Thumb Icon and mark as Correct.