Knowledge Versioning by script

iagruthijonnaga
Giga Contributor

Hi All,

 

I Have knowledge version plugin enabled, to create knowledge version we basically use OOB UI action, but now that need is, i have a condition to retire an article and now once the article gets retired versioning need to be created automatically with out clicking UI action.

Needed help on how this can be implemented.

 

 

Thanks 

Jagruthi.J 

1 ACCEPTED SOLUTION

Hi Sachin,

 

Thanks

But i achieved it through schedule job based on some other field date, using the same script as of checkout ui action by calling the script include.

 worked like this.

 

var dt = new GlideDate();
dt.getByFormat("MM-dd-yyyy");
var tb = new GlideRecord('kb_knowledge');
tb.addQuery('workflow_state', 'published');
tb.addQuery('published', dt);
tb.query();
while(tb.next()){
var newRecord = new KBVersioning().checkout(tb);
gs.log("newRecord:"+newRecord);
if(newRecord){
gs.addInfoMessage(gs.getMessage("A new version of the article is created for revision."));
//action.setRedirectURL(newRecord);
tb.update();
}
else
gs.addErrorMessage(gs.getMessage("You cannot checkout this article as it is already checked out."));

}

Regards,

Jagruthi.J

 

View solution in original post

6 REPLIES 6

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,

 

Not sure what you are after here. Do you want a new version to be created for retiring?

 

//Göran

sachin_namjoshi
Kilo Patron
Kilo Patron

You can create business rule to create new kb article versioning after kb article is retired.

You can use below sample code to create new version.

 

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")));
}
}

 

Regards,

Sachin

but... why create a new version if it's retired? make no sense... Totally against OOB functionality and how it works...

Minor revisions include updates to an article that has not yet been published. Major revisions include updates to an article that has been published and is available to customers.

This is how article versioning works OOB.You can always update minor version which isn't published yet.

 

Author here is asking about ways to achieve custom functionality for publishing KB article.

 

Regards,

Sachin