copy all attachments from child to parent record when child record is completed && delete the duplicate attachments from parent record when copying the attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 02:29 AM
I have done the work on coying all the attachments from parent to child record when child record is created and it works fine.
Now, I need to copy all attachments from child to parent record when child record is completed && delete the duplicate attachments from parent record when copying the attachments from child record. How can I do this?
We can take the example of incident and incident task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 02:37 AM
HELLO ,
YOU CAN DO THIS
var gr = new GlideRecord('your_parent_table');
gr.addQuery('your_query');
gr.query();
if(gr.next())
{
var attach = new GlideSysAttachment();
attach.deleteAll(gr);
attach.copy('child_table',child_table_record_sys_id, 'parent_table',gr.sys_id);
}
Hope this helps
Mark the answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 02:59 AM
Im confused with first query here?
var gr = new GlideRecord('x_pgpl2_spend_pre_contract');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
var attach = new GlideSysAttachment();
attach.deleteAll(gr);
attach.copy('x_pgpl2_spend_pre_contract_task', current.sys_id, 'x_pgpl2_spend_pre_contract', gr.sys_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 03:07 AM
hey
No so you glide recorded the current parent table record and then deleting all the attachments attached to that parent record
Just replace the child record sys_id in the second parameter and it will attach the attachments
var gr = new GlideRecord('x_pgpl2_spend_pre_contract');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
var attach = new GlideSysAttachment();
attach.deleteAll(gr);
attach.copy('x_pgpl2_spend_pre_contract_task','child_record_sys_id', 'x_pgpl2_spend_pre_contract', gr.sys_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 06:32 AM
Didn't work. It was not copying any attachments to parent record. here whats the
'child_record_sys_id'