- 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 - last edited yesterday
Hi @G Ponsekar are you sure this Script and these Conditions are 100% accurate/correct?
The script is greened out when I am pasting it into my script box, exactly as you have written it?
Also - there is no condition called 'Parent Changes from Empty' that does not exist as a condition option?
Please advise for complete accuracy, thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @WazzaJC ,
I haven't provided you with entire script. I just asked you to use the function GlideSysAttachment in your code to copy the attachments from child to parent
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I will recommend avoid copying files as it will increase attachment table size.
Instead check this link and show those as related list and users can see them, with this the files stays only on parent
TNT: "Related Attachments" Related List
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 you still require to attach then have after insert Business rule on "sn_si_incident"
After Insert
Condition: Parent [IS NOT EMPTY]
Script: Use this script. ensure you use the correct parent field in that table which holds PARENT
(function executeRule(current, previous /*null when async*/ ) {
new GlideSysAttachment().copy('sn_si_incident', current.parent, 'sn_si_incident', current.sys_id);
})(current, previous);
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
Hi Ankur, many thanks again, this doesn't seem to work for me. Should it be After Insert and Update ? Also, the name of the Parent incident field for my client is : 'parent_security_incident'. Can you let me know the amended details I should use in the Script and should it be After Insert and Update ? Many thanks Ankur