- 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-02-2022 02:32 AM
Here we go:
var encodedQuery = 'active=true'; //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.addQuery('related_kb_knowledge.workflow_state', 'retired' )
grRelated.query();
grRelated.deleteMultiple();
}
Please mark Helpful
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 03:13 AM
Hi
Can you tell me where i can check this from, As we are using a custom table for related articles. Like kb_2_kb i replaced with the custom table 'u_knowledge_related'...So if i add the code as below would it work the same...Or I should change the related_kb_knowledge to something else?
related_kb_knowledge.workflow_state

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 03:25 AM
This is getting a little bit too far. You had a requirement, you have the answer. basically, you have the logic. Go check your custom table, see how the fields are named there and just adjust my code to work for your custom setup. I have no way, nor the time to, to know how your custom setup does look like.
Thank you!
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024