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 02:16 PM
I am not sure about this.. I can post the screenshoots of the related list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 02:21 PM
Can post a screenshot of a "case" and the related lists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 03:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 03:16 PM
Just try the below script. Let me know if it worked for you or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 03:05 PM
The below script will copy attachments inserted on 'incident' to the problem given in the problem field on incident form.
Business rule after insert on 'sys_attachment':
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
gs.log('hello');
var incGr = new GlideRecord('incident');
incGr.addQuery('sys_id', current.table_sys_id);
incGr.query();
while(incGr.next()){
gs.log(incGr.sys_id);
var gr = new GlideRecord('problem');
gr.addQuery('sys_id', incGr.problem_id);
gr.query();
while(gr.next()){
GlideSysAttachment.copy('incident', current.table_sys_id, 'problem', gr.sys_id);
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id', gr.sys_id);
attach.query();
while(attach.next()){
if(attach.file_name != current.file_name){
attach.deleteRecord();;
}
}
}
}
}
Let me know if it works for you or not.