The CreatorCon Call for Content is officially open! Get started here.

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

I'd try that on one article before doing more:

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('workflow_state', 'draft');

gr.addQuery('sys_id', 'get_an_articles_sys_id');
gr.query();
while (gr.next()){
gr.workflow_state = 'review';
gr.setWorkflow(false);
gr.update();
}

 

The 'while' is supposed to do that if the query is correct.  Can you go to a List View of the articles you want this to apply against, and then 'copy query' from the breadcrumb and post it?  

This is the query.

sys_created_onON2018-10-26@javascript:gs.dateGenerate('2018-10-26','start')@javascript:gs.dateGenerate('2018-10-26','end')^workflow_state=draft

OK, try:

 

var gr = new GlideRecord('kb_knowledge');
//gr.addQuery('workflow_state', 'draft');
gr.addEncodedQuery('sys_created_onON2018-10-26@javascript:gs.dateGenerate('2018-10-26','start')@javascript:gs.dateGenerate('2018-10-26','end')^workflow_state=draft');
gr.query();
while (gr.next()){
gr.workflow_state = 'review';
gr.update();
}

Though I don't see anything there that should cause it to run any differently.

 

Same result 😞