can we send mail for duplicate knowledge article in servicenow

SabyasachiM8774
Tera Contributor

I Have a huge number of duplicate knowledge article, I want to send the work group owners an email notification so that they can check and remove the unnecessary one. 

2 REPLIES 2

Sai_Charan_K
Kilo Sage

Hi @SabyasachiM8774 ,

Assuming that you are finding the duplicates by same short description please find the below script which enables you to get all the sys_id's in an array.

var arr=[];
var agg = new GlideAggregate('kb_knowledge');
agg.addAggregate('COUNT', 'short_description');
agg.orderBy('short_description');
agg.addQuery('active', 'true');
agg.query();

while (agg.next()) {
    var kbCount = parseInt(agg.getAggregate('COUNT', 'short_description'), 10);

    // Display only if the count is greater than 1
    if (kbCount > 1) {
        gs.info('Short Description "{0}" has a count of {1}. KB Articles:', [agg.short_description, kbCount]);

        // Query again to get the individual KB articles with this short_description
        var kb = new GlideRecord('kb_knowledge');
        kb.addQuery('short_description', agg.short_description);
        kb.addQuery('active', 'true');
        kb.query();

        while (kb.next()) {
			arr.push(kb.sys_id.toString());
            gs.info('- KB Number: {0}, KB Sys ID: {1}', [kb.number, kb.sys_id]);
        }
    }
}
gs.print(arr);


You can call an event that triggers your email by sending the array values to the event as parameters. 

Please mark my answer "Helpful" and "correct" if you feel that it has helped you in any way.

Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India

SabyasachiM8774
Tera Contributor

Thank you for sharing the information that helps,

While I was extracting the report there were multiple duplicate articles for same work group. Please help how can I send emails to the work groups who are having duplicate articles. In the report I saw at least there are 100 and more work groups having duplicate article. Need to send mail separately each workgroup without sharing data.