Attaching the knowledge article from parent incident to child incident automatically

Nafisa Zaman
Tera Contributor

Attaching the knowledge article from parent incident to child incident through script. But when i am creating new child incident Duplicate KB article is attaching. Please guide me why this is happening

 

(function executeRule(current, previous /*null when async*/) {

// // Add your code here
// if(current.task.sys_class_name == 'incident')

 
var parent = current.sys_id;

var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', parent);
inc.query();
while(inc.next())
{  
var kn1 = new GlideRecord('m2m_kb_task');
kn1.addQuery('task',kn1.task.p);

kn1.initialize();
kn1.task = inc.sys_id.toString();
kn1.kb_knowledge=current.u_ka_attached;

kn1.insert();  
}
 

})(current, previous);
2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @Nafisa Zaman 

 

Modify your script with mine :-

 

(function executeRule(current, previous /*null when async*/) {

// // Add your code here
// if(current.task.sys_class_name == 'incident')

 
var parent = current.sys_id;

var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', parent);
inc.query();
while(inc.next())
{  
var kn1 = new GlideRecord('m2m_kb_task');
kn1.addQuery('task',kn1.task.p);

kn1.initialize();
kn1.task = inc.sys_id.toString();
kn1.kb_knowledge=current.u_ka_attached;

kn1.insert();  
var attach = new GlideSysAttachment();
attach.deleteAll(current.sys_id);

}
 

})(current, previous);

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

When i am going to create a new child in parent new child is created but in every child duplicate KA is coming.
i dont want duplicate KA attach to my child incident.