- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 09:53 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2014 01:36 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 12:48 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 01:43 PM
Thank you Mark, I really appreciate it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2014 01:36 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2014 01:44 PM
Thank you so much Mark. I'll give that a try first thing in the morning. I really appreciate your time on this..:))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2014 05:56 AM
Hey Mark,
That works perfect. Again, thank you so much for all your help..:)