Script/Business Rule to copy Attachments from Child Security Incident to Parent Security Incident

WazzaJC
Tera Expert

Script/Business Rule to copy Attachments from Child 'Security Incident' to Parent 'Security Incident'

 

Dear ServiceNow Community Colleagues, I would greatly appreciate your help/guidance on how to achieve the following.

 

I need to configure for my client, so that when a Child Security Incident is related/linked to a Parent Security Incident, that attachments that are on the child security incident record are copied across as attachments on the Parent Security Incident record.

 

Please could you let me know the Business Rule / Script that I need to achieve this, also minimising any performance issues when doing this. Does it need to be an Insert, Update or Async Business Rule? 

 

It is all related to 'Security Incident Response', so the table is 'sn_si_incident'. 

 

Both the child ticket and parent ticket would be Security Incident, on the same table: sn_si_incident

 

Thanks very much for your help.

 

Kind Regards.

 

2 ACCEPTED SOLUTIONS

Hi @WazzaJC ,

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the record has a parent
    if (!current.parent_incident) {
        return;
    }

    // Get the parent Security Incident record
    var parent = new GlideRecord('sn_si_incident');
    if (!parent.get(current.parent_incident)) {
        return;
    }

    // Copy attachments from the child to the parent
    var attachments = new GlideRecord('sys_attachment');
    attachments.addQuery('table_name', 'sn_si_incident');
    attachments.addQuery('table_sys_id', current.sys_id);
    attachments.query();

    while (attachments.next()) {
        GlideSysAttachment.copy('sn_si_incident', current.sys_id, 'sn_si_incident', parent.sys_id);
    }
})(current, previous);

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

View solution in original post

@WazzaJC

the business rule is meant to work when you add file on Child, it will copy to parent

What's your business requirement?

1) when child incident is created from parent then file from Parent should be copied -> for this I already shared logic above

AnkurBawiskar_0-1756997747981.png

 


OR

2) when file is attached to child, add that same to parent -> for this I already shared logic above

AnkurBawiskar_1-1756997776092.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

23 REPLIES 23

@WazzaJC 

If my response(s) helped please mark them correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I still can't get it to work Ankur, with the Script and conditions mentioned (as exactly above) but I am trying again now. For now, this config is not working for me.

@Ankur Bawiskar does my Business Rule have to be done within the Scope: 'Security Incident Response' rather than 'Global' Scope, would this make any difference? I have done it all per your direction in Global Scope but it doesn't seem to work as yet. Thanks.

@WazzaJC 

yes please use Security Incident Response for BR

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks again @Ankur Bawiskar . I just can't get it to function using the above and using Security Incident Response Scope. When I test it, linking a child security incident to the parent security incident and then 'save', the attachments that exist on the child record do not pull through to the related parent record. I just can't get this to work.