How to invoke UI Action using background or fix script.

dvelloriy
Kilo Sage

Hi Community,

I have around 500 KB articles which are currently in draft state. There is a button at the top "Submit for review" when clicked it changes the state of knowledge article to publish. 

How can i invoke this button "Submit for review" for all 500 articles at once.

1. Article in draft state.

find_real_file.png

 

2. When we click on "Submit for review".

find_real_file.png

 

3. Ui Action "Submit for review".

Condition : current.workflow_state == 'draft' && (current.author == gs.getUserID() || gs.hasRole('knowledge_admin') || gs.hasRole('knowledge_mgr'))

Script: 

action.setRedirectURL(current);
current.workflow_state = 'review';
current.update();

Any help on this would be appreciated.

1 ACCEPTED SOLUTION

I deep dived into it and looked for this issue on the web and i think i found it. I replaced gr with some other variable name and i think it resolved the issue.

This is the article.

https://community.servicenow.com/community?id=community_question&sys_id=e61343e1dbd8dbc01dcaf3231f96190c

View solution in original post

12 REPLIES 12

Shane J
Tera Guru

GlideRecord script (I think this is all you need):

 

 

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('workflow_state', 'draft');
gr.query();
while (gr.next()){
gr.workflow_state = 'review';
gr.update();
}

 

https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/concept/c_UsingGlideRecordToQueryTables.html

Thanks Shane.

Got this when ran the background script. Articles are still in draft state. Any idea?

[0:00:00.676] Script completed in scope global: script


ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Begin(80abbfb4109a91c090483055ab86544c): event=update
completed Approval: Peer Review(3b9b7fb4109a91c090483055ab8654dd): event=execute
completed Saved as Draft(bb9b7fb4109a91c090483055ab8654db): event=execute
completed If Policy(ccabbfb4109a91c090483055ab865445): event=execute
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Begin(a85c8aa6100ed98090483055ab865403): event=update
completed If the Topic is News(e45c8aa6100ed98090483055ab86549e): event=execute
completed Wait for Retired(e45c8aa6100ed98090483055ab86548e): event=execute
completed Wait for 2 Weeks(245c8aa6100ed98090483055ab865405): event=execute
*** Script: Scheduling: WFTimer4e52bfb213ede300a8e2bc122244b00c for: 11-08-18 09:52:26 AM
completed Check everyday(645c8aa6100ed98090483055ab865481): event=execute
completed Publish Article(0cabbfb4109a91c090483055ab865437): event=execute
completed Notify Author: Published(88abbfb4109a91c090483055ab86543b): event=execute
completed Delete this workflow(0cabbfb4109a91c090483055ab86544a): event=execute
completed End(8cabbfb4109a91c090483055ab86540e): event=execute

i think it ran just for 1 article which got published. how to run it through the loop for all articles?

It should run for all the articles which are in draft. However, try running the below script.

 

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('workflow_state', 'draft');
gr.query();
while (gr.next()){
gr.workflow_state = 'review';
gr.setWorkflow(false);
gr.update();
}

 

Thanks,

Sunil Safare