How to send one notification to same user for his multiple records

Amrutha K V
Tera Contributor

Hi Team,

If same inactive owner(testuser1) having multiple knowledge base records(Email,Knowledge,IT) in Knowledge base table, then we have to send only one notification to a particular DL (ABCD@servicenow.com) that owner is terminated for all these knowledge base records: Email,Knowledge,IT.

Could you please help me with the script if possible. 

Thank you!

3 REPLIES 3

Manoj89
Giga Sage

Hi Amrutha,

 

For this, I would create a report and schedule it.

Hi Manoj,
Thank you for quick reply.
We have to implement in Scheduled Job.
Now I am using the below script, but if the same inactive owner having multiple kb records, then it is triggering multiple emails for the DL. In this case I want to send only one notification to DL. 

var kbaseowner = new GlideRecord('kb_knowledge_base');

    kbaseowner.addEncodedQuery('owner.active=false');
    kbaseowner.query();
    gs.log("javascript" + kbaseowner.getRowCount());
    while (kbaseowner.next()) { // if the user is found
        gs.eventQueue("kb.kbmanagers.empty",kbaseowner);
    }


Could you please correct me if possible with the script.
Thank you!

Manoj89
Giga Sage

Hi Amrutha,

 

Try something like this

var kbOwners = [];
var kbaseowner = new GlideRecord('kb_knowledge_base');
kbaseowner.addEncodedQuery('owner.active=false');
kbaseowner.query();
gs.log("javascript" + kbaseowner.getRowCount());
while (kbaseowner.next()) { // if the user is found
        kbOwners.push(kbaseowner.owner);
 }

var arrayUtil = new ArrayUtil();
var finalArray = arrayUtil.unique(kbOwners);

finalArray.forEach(createNotificationEvent);

function createNotificationEvent(ev){
     gs.eventQueue("kb.kbmanagers.empty",ev);
}