how to fetch the attachments from parent task to child tasks

lakshman nalla
Tera Contributor

hi 

 

we have a requirement, attachments that requester added and parent task's attachments all should be Shown in the child task.

1 ACCEPTED SOLUTION

Mary9
Tera Guru

You have a couple options:

 

  1. Copy the attachments from the parent to the child via the GlideSysAttachment copy method
  2. Or create a Related List with a relationship between sys_attachment and the child table. See documentation. In the relationship, Applies to table = <your child table> and Queries from table = sys_attachment. Queries with:

 

current.addQuery('table_name', '<parent table name>');
current.addQuery('table_sys_id', parent.<name of reference field to parent>);​

 

View solution in original post

4 REPLIES 4

Mary9
Tera Guru

You have a couple options:

 

  1. Copy the attachments from the parent to the child via the GlideSysAttachment copy method
  2. Or create a Related List with a relationship between sys_attachment and the child table. See documentation. In the relationship, Applies to table = <your child table> and Queries from table = sys_attachment. Queries with:

 

current.addQuery('table_name', '<parent table name>');
current.addQuery('table_sys_id', parent.<name of reference field to parent>);​

 

hi @Mary9 

 

i need to show the attachments in the parent task that attachments added in child tasks i need solution also for this

To show attachments from children on the parent you'd just create another Related List relationship:

 

Applies to table = <your parent table>

Queries from table = sys_attachment

Queries with:

// Get child task sys_ids
var parentTaskId = parent.getUniqueValue();
var gr = new GlideRecord('<child table name>');
gr.addQuery('<name of reference field to parent>', parentTaskId );
gr.query();

var childTaskIds = [];

while (gr.next()) {
    childTaskIds.push(gr.getUniqueValue());
}

// Query attachments on child tasks
current.addQuery('table_name', '<child table name>');
current.addQuery('table_sys_id', 'IN', childTaskIds);

 

Jaspal Singh
Mega Patron
Mega Patron

Hi Lakshman,

You can create relationship and show attachments as related list. This will help avoiding duplicating the attachments which may be have some storage size consumption over the period of time.

Check article that I had published some time ago.