attachment getting duplicated when parent to child record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 10:44 PM
HI All,
i'm trying to attach attachment to parent --> its attached to child record
but when i attach 2nd attachment --> 1st one duplicated and 2nd attached
3rd time its increased more ....i want to fix this issue in businessrule
(function executeRule(current, previous /null when async/ ) {
// Add your code here
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_name', 'incident');
attachment.query();
if (attachment.next()) {
var gr = new GlideRecord('u_azure_devops');
gr.addQuery('parent', current.getUniqueValue());
gr.query();
if (gr.next()) {
// Check if the attachment already exists on the destination record
var existingAttachment = new GlideRecord('sys_attachment');
existingAttachment.addQuery('table_name', 'u_azure_devops');
existingAttachment.addQuery('table_sys_id', gr.getUniqueValue());
existingAttachment.addQuery('file_name', attachment.file_name);
existingAttachment.query();
if (!existingAttachment.next()) {
GlideSysAttachment.copy('incident', current.getUniqueValue(), 'u_azure_devops', gr.getUniqueValue());
}
}
}
})(current, previous);
please correct my code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 01:59 AM
Hi @vardini ,
Please update your script like below and try.
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id",current.sys_id);
gr.addQuery("table_name","u_azure_devops");
gr.query();
if(gr.getRowCount()==0) {
//add your copy script here
GlideSysAttachment.copy('incident', current.parent, 'u_azure_devops', current.sys_id);
}
Please refer below link and try the same.
Please mark my answer as helpful and correct if it helps to resolve your issue.
Regards,
Namrata