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 12:51 AM
Hi @Snow Tomcal ,
You can create BR like below :-
Script :-
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
new global.KnowledgeUIAction().publish(current);
})(current, previous);
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 01:08 AM
Hi, looks really good but sadly my article still hasn't published. I can't seem to find why
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 01:12 AM
Hi @Snow Tomcal ,
That code will triggered the workflow. So your article might go into the review state for approval. after approval it gets published.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 01:13 AM
I used the Instant publish workflow, but the workflow state stayed draft