- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 01:11 PM
Can I run the instant publish on articles already in draft state?
The articles have been created and vetted by our Knowledge team so I just need to move them to a published state. Is this possible?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 08:55 AM
Okay, this is hastily knocked up, and seems to work on articles that are currently draft but NOT "review":
(edited - <pre> tags barfed)
gs.log("1. Starting 'update-kb' script","UPDATE-KB");
gs.setSession.setStrictQuery(true);
// -- first, we use a GlideRecord against the Knowledgebase table
var pending = new GlideRecord('kb_knowledge');
// -- create our query:
pending.addEncodedQuery('workflow_state=draft^ORworkflow_state=review');
// -- call that query:
pending.query();
gs.log("2. found " + pending.getRowCount() + " records to update.","UPDATE-KB");
// -- now update each record found:
while(pending.next())
{
// -- flick workflow state over
gs.log("3. changing: " + pending.number + " to PUBLISHED.","UPDATE-KB");
pending.workflow_state = 'published';
pending.update();
}
gs.log("4. Completed script","UPDATE-KB");
This should write out to your script log, but under a different "source" so it should identify the records that have been amended, should you need an audit trail. I trust you'll run it on a testbed first!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 11:32 AM
Script worked and changed all the articles in my test instance to published! I'll test again in sub-prod to ensure that the Knowledge Base and Categories don't change once ran!
Many thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 01:47 PM
Good stuff, fellah - glad to hear it helped!
For what it's worth, this kinda stuff (GlideRecord, background scripts, etc) is covered on our Scripting courses: Scripting in ServiceNow - if you're interested in taking coding any further.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 06:33 PM
"Workflow" is the field you are talking about - it's actually list-editable, so you could just go to a list of those articles, show the Workflow column, and then update their Workflow value to Published to instantly publish them.
EDIT: seems like out of box behavior is to disable list editing so this might not work for you. You could still set the state of these articles using a background script. Alternatively, if you think this will be a common occurrence, you could make the Publish/Retire UI actions visible in lists, so you could select multiple rows, then use the UI action on them all at the same time. See UI actions for more on that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 06:36 PM
Patrick, inline editing is sweet and I'm leaning towards that as a last effort to get this accomplished. It's just very cumbersome to do 300 times! Not impossible certainly but that's why I was hoping to somehow fan-dangle (technical term) re-running that instant publish script again and just getting these all updated at once!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 06:40 PM
If you do decide to enable list-editing like we did, you can actually edit multiple rows at once, so you could still edit multiple articles in one go. I edited my first response right after it occurred to me that we had customized it to allow list-editing, but you could tick a box on the "Publish" UI action to let it run on lists and you could get the same effect as using it on the form (but in a list).