- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:20 AM
Hi Community,
I have a requirement where all the records that are present in Related Articles(related list) in Knowledge article record to be removed from the related list but should not be deleted from the table, Only remove from related list via a script. I want to achieve this via a fix script. Could someone help me on this.
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:31 AM
Hi. You need to run this code in bg script/fix script
var current = 'd7dc75b5474321009db4b5b08b9a7150'; //Replace with sys_id of the Main record, from which you want to remove the relared articles
var grRelated = new GlideRecord('kb_2_kb');
grRelated.addQuery('kb_knowledge', current);
grRelated.query();
grRelated.deleteMultiple();
This will not delete the related articles from the kb_knowledge table, but will delete only the relationships!
Please mark Correct and Helpful if my answer helps you resolve your issue. Thanks!
Martin Ivanov
Community Rising Star 2022
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:31 AM
Hi. You need to run this code in bg script/fix script
var current = 'd7dc75b5474321009db4b5b08b9a7150'; //Replace with sys_id of the Main record, from which you want to remove the relared articles
var grRelated = new GlideRecord('kb_2_kb');
grRelated.addQuery('kb_knowledge', current);
grRelated.query();
grRelated.deleteMultiple();
This will not delete the related articles from the kb_knowledge table, but will delete only the relationships!
Please mark Correct and Helpful if my answer helps you resolve your issue. Thanks!
Martin Ivanov
Community Rising Star 2022
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:36 AM
Hi
Thanks for your response.
I want to remove the related articles for 1000's of knowledge articles. As the above code shows how to remove them for each record with sys_id. So how do we achieve it for multiple articles.
Thanks!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:45 AM
Then go to the kb_knowledge table, build your query and copy it (hope you know how to copy encoded query, let me know if you don't).
Then your script for the fix script will be
var encodedQuery = 'active=true^descriptionLIKEsomething'; //replace with yours
var grKBArticle = new GlideRecord('kb_knowledge');
grKBArticle.addEncodedQuery(encodedQuery);
grKBArticle.query();
while(grKBArticle.next()){
var grRelated = new GlideRecord('kb_2_kb');
grRelated.addQuery('kb_knowledge', grKBArticle.getUniqueValue());
grRelated.query();
grRelated.deleteMultiple();
}
Please mark Correct and Helpful if my answer helps you resolve your issue. Thanks!
Martin Ivanov
Community Rising Star 2022
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 02:22 AM
Hi
Thanks for the answer. That helped me achieve the solution. I also want this part where i want to remove only the related articles whose state is retired and not other related articles which are published. How do we achieve this?
Thanks!