When an email is being processed by an inboud action, attachments are being automatically copied to the target record. But in a case we want to duplicate them somewhere else, such code can be used for this.
Assuming it could be a script of an inbound action for the sc_task
table.
/**
* Copy attachments to parent RITM
* so attachments will be at Task and at RITM
*/
var emailSysId = sys_email.getUniqueValue();
var grParent = current.parent.getRefRecord();
if (sys_email.hasAttachments()) {
var table = grParent.getTableName();
GlideSysAttachment.copy(
table,
grParent.getUniqueValue(),
sys_email.getRecordClassName(),
emailSysId
);
}