Attachment added from RITM to SCTASK and SCTASK to RITM Vice Versa Incase of deletion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 06:57 AM
Hi All,
I have requirement like in the below scenarios:
1) If any attachment is added to RITM I need to copy that attachment to SC task.
In this case i need to update Additional comments in RITM attachment added with file name and in sctask I need to update work notes Attachment "file name" copied from RITMNumber.
2)If any attachment is added to sctask I need to copy that attachment to RITM.
In this case I need to update work notes in sctask like this a Attachment file name added and in RITM comments like Attachment file name copied from sctasknumber.
3)If Any attachment is deleted in RITM and same attachment need to be deleted from sctask.
In this case I need to update comments in RITM Attachment file names is removed and sctask Attachment file name is removed from RITM and same in sctask like this.
4)If Any attachment is deleted in Sctask and same attachment need to be deleted from RITM.
In this case work notes in sc task Needs to update to attachment file name removed and RITM comments Attachment file name has been removed from sctask and RITM.
For all these requirements I have written one business rules as per the below:
Table: sys_attachment
When to run: After - Insert & Delete
In Advance condition Iike below:
current.table_name=="sc_req_item" || current.table_name=="sc_task"
Script is like below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 08:21 AM - edited 02-20-2025 08:42 AM
Hi @Sirri ,
Try below line of code to copy attachment from RITM to Sc_task and vice versa.
Syntax to copy attachment:
var attachment = new GlideSysAttachment();
attachment.copy(String sourceTable, String sourceID, String targetTable, String targetID)
Example to copy from Incident table to Problem
var attachment = new GlideSysAttachment();
var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', problemSysID);
To break the occurrences of infinite loop add the filter condition as below.
Mark it as correct/helpful if this answers your query.
Best Regards,
Pooja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 08:33 AM
@Pooja58 ,
It will copy duplicate attachment when we added second attachment. Please let me know apart from this how we can achieve
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 08:58 AM
@Sirri
1) Business Rule 1:
(After insert) table:sys_attachment
2)Business Rule 2:
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Pooja.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 01:11 AM
Thank you for your response.
I have observed below points in testing:
1)If we add second attachment it is copying first and second after copying first one duplicated is copying once again as per the script.
2) When we add attachment in RITM or sctask comments not updating like this attachment added. But copied comments are updated correctly but it's showing sys id in comments (Attachment 'At or after filter Last 6 months.PNG' copied from SCTask 91d1b86a83331210b104c670ceaad354)
Please can your correct your script and give exact one after testing.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 01:17 AM
Doesn't sound a valid use-case to copy same file on another record.
It will increase the table size for attachment.
use the related list feature
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