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 03:09 AM
Hello,
Please check with below script:
var parentRecord = new GlideRecord('x_pgpl2_spend_pre_contract');
parentRecord.addQuery('sys_id', current.sys_id);
parentRecord.query();
if (parentRecord.next()) {
var glideAttachment = new GlideSysAttachment();
glideAttachment.deleteAll(parentRecord);
glideAttachment.copy('x_pgpl2_spend_pre_contract_task', current.getValue("sys_id"), 'x_pgpl2_spend_pre_contract', parentRecord.getValue("sys_id"));
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 06:24 AM
Didn't work. It was not copying any attachments to parent record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 08:35 AM
Hello Vijaya,
My apologise I think I pasted incorrect code. Could you please check once with below code:
var parentRecord = new GlideRecord('x_pgpl2_spend_pre_contract');
parentRecord.addQuery('parent', current.getUniqueValue());
parentRecord.query();
if (parentRecord.next()) {
var glideAttachment = new GlideSysAttachment();
glideAttachment.deleteAll(parentRecord);
glideAttachment.copy('x_pgpl2_spend_pre_contract_task', current.getValue("sys_id"), 'x_pgpl2_spend_pre_contract', parentRecord.getValue("sys_id"));
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 03:24 AM
tried with this but didn't worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 04:30 AM
I found the solution with below script:
(function executeRule(current, previous /*null when async*/ ) {
var parentRecord = new GlideRecord('x_pgpl2_spend_pre_contract');
parentRecord.addQuery('number', current.parent.number);
parentRecord.query();
// var rowCount = parentRecord.getRowCount();
// gs.info('RowCount is: ' + rowCount);
if (parentRecord.next()) {
var at = new GlideRecord('sys_attachment');
at.addQuery('table_sys_id', current.parent.sys_id);
at.query();
if (at.next()) {
at.deleteMultiple();
}
GlideSysAttachment.copy('x_pgpl2_spend_pre_contract_task', current.sys_id, 'x_pgpl2_spend_pre_contract', parentRecord.sys_id);
}
})(current, previous);