copy attachments to case to incident and vice-versa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 09:43 AM
Hello Community,
My requirement is to copy attachments from case to the incident i.e.,(when ever we added an attachment to the case that should also be seen in the related incident ) and also Vice-versa the opposite way. I tried with writing a business rule (for copying attachments to case-incident) on Sys_attachment table.
After - Insert
script :
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var incGr = new GlideRecord('incident');
incGr.addQuery('case', current.sys_id);
incGr.query();
while(incGr.next())
{
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', incGr.sys_id);
gr.deleteMultiple();
GlideSysAttachment.copy('sn_customerservice_case', current.table_sys_id, 'incident', incGr.sys_id);
}
})(current, previous);
This didnt work for me and also this is landing no where(I am unable to attach or close after activating the BR.). Any help will be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 11:09 AM
Hi,
Try below code :
Condition : current.table_name == '<table of which you want to copy the attachment>'
var incGr = new GlideRecord('incident');
incGr.addQuery(<'field name which in on incident and refer the table(case) of which you want to copy the attachment'>, current.table_sys_id);
incGr.query();
if(incGr.next())
{
GlideSysAttachment.copy('<soruce tabele name>', current.table_sys_id, 'incident', incGr.sys_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 12:50 PM
table-Attachment(sys_attachment)
after-insert
condition : Condition : current.table_name == 'case'
script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var incGr = new GlideRecord('incident');
incGr.addQuery('parent',current.table_sys_id);
incGr.query();
if(incGr.next())
{
GlideSysAttachment.copy('case', current.table_sys_id, 'incident', incGr.sys_id);
}
})(current, previous);
This is the way I did.This didn't worked . Can you suggest me any modifications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 01:32 PM
Instead of copying the attachments, why not create a Defined Related List to expose the related attachments? This way you aren't duplicating the attachment in the event that it gets updated on one record. More about creating defined related lists can be found here:
http://wiki.servicenow.com/index.php?title=Creating_Defined_Related_Lists#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 02:06 PM
Hi Srikanth,
Do the case table have any field that reference to the related incident?