Background script not working

sohan_snow
Tera Contributor

Hi All,

Trying to run a background script to replace "author" in some KB articles.


Below is the script, executing which returns "***Script:0". Kindly assist as to what is wrong in the below script

var obj= new GlideRecord('kb_knowledge');
obj.addQuery('author','8aef1935474321009db4b5b08b9a7113');               //sys of the author to be replaced from KB articles
obj.query();
gs.print(obj.getRowCount());

while(obj.next())
{
obj.author= 'e6f8e8cb4f52320065fa4a318110c7f7';                                                               // this sys id replaces as the new author for KB articles
obj.setWorkflow(false);
obj.update();
}

Thanks in advance

1 ACCEPTED SOLUTION

Replace the query that you obtain from the list view, in this script and execute it.



var obj= new GlideRecord('kb_knowledge');


obj.addEncodedQuery(query);   //Replace your query here              


obj.query();


gs.print(obj.getRowCount());



while(obj.next()){


obj.author= 'e6f8e8cb4f52320065fa4a318110c7f7';                                                              


obj.setWorkflow(false);


obj.update();


}





Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


View solution in original post

3 REPLIES 3

Alikutty A
Tera Sage

The sys_id of author should be incorrect or there are no articles with the above user as author.



Can you apply this filter on the knowledge article list view and copy its query once



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


Replace the query that you obtain from the list view, in this script and execute it.



var obj= new GlideRecord('kb_knowledge');


obj.addEncodedQuery(query);   //Replace your query here              


obj.query();


gs.print(obj.getRowCount());



while(obj.next()){


obj.author= 'e6f8e8cb4f52320065fa4a318110c7f7';                                                              


obj.setWorkflow(false);


obj.update();


}





Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


Hi Alikutty, thanks a ton for you asisstance