Using script to update workflow state in a new Knowledge Base

Kaysi Braden
Kilo Contributor

I'm not terribly familiar with javascript and I'm wondering if someone can provide a little guidance. I'm trying to update a script previously used to push a different attribute of a group of Knowledge articles. The idea is that we have a new Knowledge Base going live and want to push the articles in that Knowledge Base from Draft to Published. But when I run it (update commented out and gs.print added to show how many articles it would try to update), it's giving me a much larger number than I would expect. Can someone tell me what I'm doing wrong?

var articleGR = new GlideRecord('kb_knowledge');
articleGR.query('workflow_state=draft^kb_knowledge_base=d947098ddbef8410be9189584b96197f');
gs.print(articleGR.getRowCount());
while (articleGR.next()) {
    articleGR.setValue("workflow_state", "published");
    articleGR.autoSysFields(false); //prevent updated by to update
    articleGR.setWorkflow(false); //prevents business rules
    //articleGR.update(); //uncomment when ready to actually update
}

 

Thank you!

1 ACCEPTED SOLUTION

Hi Kaysi,

 

Few changes as variable name was not passed correctly. Below should do the trick

var articleGR = new GlideRecord('kb_knowledge');
articleGR.addEncodedQuery('workflow_state=draft^kb_knowledge_base=d947098ddbef8410be9189584b96197f');
articleGR.query();
gs.print(articleGR.getRowCount());
while (articleGR.next()) {
    articleGR.setValue("workflow_state", "published");
    articleGR.autoSysFields(false); //prevent updated by to update
    articleGR.setWorkflow(false); //prevents business rules
    //articleGR.update(); //uncomment when ready to actually update
}

View solution in original post

5 REPLIES 5

Kaysi Braden
Kilo Contributor

That gives me the expected count! Thank you so much!