Attach KB article to Change Task

alhicks
Tera Guru

We're trying to add a KB article to the Attached Knowledge related list, from a Workflow.     We need one of our existing KB article's to always be attached to the Change Task that are created from one of our Workflows.       We're unable to find a way to do this.

1 ACCEPTED SOLUTION

Good afternoon Andrea,



I think the script below will get you what you are looking for.   The script is first finding all the change task that you just created off the current change.   Once it identifies the change tasks it will open the Attached Knowledge related table and will insert a KB (KBxxxxxxx) and then open the next change task record and perform the same action.   Just replace KBxxxxxx with your KB number and it should work (did on my instance).   One other thing I had to do was look at my ACL's for the m2m_kb_task table so I could insert records.



attach_kb();



function attach_kb() {


            var rec_task = new GlideRecord('change_task');


            rec_task.addQuery('change_request', current.sys_id);


            rec_task.query();


                      while (rec_task.next()) {


                                var rec_kb = new GlideRecord('m2m_kb_task');


                                rec_kb.initialize();


                                rec_kb.task = rec_task.sys_id;


                                rec_kb.kb_knowledge.setDisplayValue('KBxxxxxx');


                                rec_kb.insert();


  }


}



Hope this works



Mark


View solution in original post

9 REPLIES 9

Hi Andrea,



The script will go behind the task creation objects.   Create them first then you will run the script on them.   The script I provided above will not work on this (working of fixing it now).



Mark


Thank you Mark, I really appreciate it.


Good afternoon Andrea,



I think the script below will get you what you are looking for.   The script is first finding all the change task that you just created off the current change.   Once it identifies the change tasks it will open the Attached Knowledge related table and will insert a KB (KBxxxxxxx) and then open the next change task record and perform the same action.   Just replace KBxxxxxx with your KB number and it should work (did on my instance).   One other thing I had to do was look at my ACL's for the m2m_kb_task table so I could insert records.



attach_kb();



function attach_kb() {


            var rec_task = new GlideRecord('change_task');


            rec_task.addQuery('change_request', current.sys_id);


            rec_task.query();


                      while (rec_task.next()) {


                                var rec_kb = new GlideRecord('m2m_kb_task');


                                rec_kb.initialize();


                                rec_kb.task = rec_task.sys_id;


                                rec_kb.kb_knowledge.setDisplayValue('KBxxxxxx');


                                rec_kb.insert();


  }


}



Hope this works



Mark


alhicks
Tera Guru

Thank you so much Mark.   I'll give that a try first thing in the morning.   I really appreciate your time on this..:))


alhicks
Tera Guru

Hey Mark,



That works perfect.   Again, thank you so much for all your help..:)