How do you get the attachment's sys_id that is on the kb_knowledge

feco
Kilo Contributor

How does the table kb_knowledge link to sys_attachment.   I'm trying to get the sys id of the attachment that is on the kb_knowledge.

1 ACCEPTED SOLUTION

Mihir Mohanta
Kilo Sage

Hi Florence,


Write a business rule on the Knowledge table.



Inside script, write a Glide query to sys_attachment table.Like,



var attachment = new GlideRecord('sys_attachment');


attachment.addQuery('table_sys_id',current.sys_id);


attachment.query();


while(attachment.next()){


gs.addInfoMessage('sys_id of the attachment is : ' +attachment.sys_id);


}



Thanks,


Mihir


View solution in original post

13 REPLIES 13

Mihir Mohanta
Kilo Sage

Hi Florence,


Write a business rule on the Knowledge table.



Inside script, write a Glide query to sys_attachment table.Like,



var attachment = new GlideRecord('sys_attachment');


attachment.addQuery('table_sys_id',current.sys_id);


attachment.query();


while(attachment.next()){


gs.addInfoMessage('sys_id of the attachment is : ' +attachment.sys_id);


}



Thanks,


Mihir


StephLindorff
Tera Expert

You can also just right click on the attachment and Copy Shortcut (if your browser has that option).   The SysID will be in that URL:



xxxxx.service-now.com/sys_attachment.do?sys_id=f20f4fda6f429200e4ec496aea3ee40e


Shahed Shah1
Tera Guru

In addition to Mihir's and Stephanie's answer, you can add the Attachments Related List to the Form. This is a custom and global relationship that does the hard work of matching up an attachment to your record (have a look in System Definition → Relationships and look for the record with the name of "Attachments").



Plus you can work with the related list as normal (such as right-click on an attachment to get its sys_id) and it's updated immediately as soon as you attach a file to the parent record.



- Shahid


feco
Kilo Contributor

Thank you all for your help.   It has been very helpful.


markk57
Tera Contributor

Just wanted to add that having the filename of the attachment associated to the sys_id is helpful as well, so the last line of the code given above by Mihir could be:

gs.addInfoMessage('sys_id of attachment - '+attachment.file_name + ' is : ' +attachment.sys_id);

This way both attributes are displayed, especially helpful when you have multiple attachments to one record.  Of course this business rule should only have a Role Condition of admin defined as well.