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

Mark Laucus
Giga Guru

What you might is to create a script object in the workflow to add this information.   The task workflow objects are limited in adding related data to a task.   Since you are on the task record you just need the knowledge article sys_id that you want to use (and it is the same all the time).  



Here is what an example script could look like.   Note: This script is not fully tested out



attach_kb() ;


function attach_kb() {


var rec = new GlideRecord('m2m_kb_task');


rec.initialize();


rec.kb_knowledge = 'Sys ID of knowledge';


rec.task = current.sys_id;


rec.insert()


}



Hope this helps.


alhicks
Tera Guru

Hey Mark,



I'm sorry, I'm not sure exactly what you mean by script object.     Thank you for the quick reply...:)


Hello Andera,



It is actually called "Run Script" (under the Utilities Branch).   This object will run Javascript on the Server Side to perform work.   In this case the script would copied into the object.   The function of the script is to new record in the Knowledge Applied to Tasks table (m2m_kb_task).   In creating the new record it will tie the task record (ctask in your case) to a KB article).   If you are unconfortable about scripting I can test the script above to make sure it works.



Mark


    I was trying the Run Script (have used it before) but it didn't seem to work.   I had actually put the Run Script in front of the Task creation, maybe that's where I went wrong.