- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2020 01:40 PM
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!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2020 02:31 PM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2020 01:56 PM
Hi Kaysi,
Can you try below & look for count.
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2020 02:22 PM
Hi Jaspal,
Thanks for trying, that still gives me the higher count. Must be something with the filter?
Kaysi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2020 02:24 PM
I just verified and it's returning the full count of all knowledge articles, not just the ones in that state and KB.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2020 02:31 PM
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
}