- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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
OR
2) when file is attached to child, add that same to parent -> for this I already shared logic above
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
If my response(s) helped please mark them correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.