- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 06:47 AM
Hi Community,
I need to copy attachment from interaction table to the case table
So I have written one after BR on the interaction related record, in this table only we have the linking for both interaction
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 08:35 AM
Here's why your Business Rule is not working and how to fix it:
Business Rule not triggering
If the Business Rule is set on a related record table and that table is not being updated when the interaction is linked to a case, then the rule won't fire. Make sure the rule is set on the correct table and event. Use conditions like "after update" where current.task or current.case becomes populated.
No need to call attachment.update()
The method GlideSysAttachment.copy() already performs the copy. There is no need to call update(), and doing so can cause issues because attachment is not a GlideRecord—it is a helper class.
Correct usage of table names
Replace 'case table' with the exact table name of your case, such as sn_customerservice_case or sn_hr_core_case.
Updated example script:
This should go in an after update Business Rule on the interaction table, assuming the case reference (task) is being updated:
(function executeRule(current, previous) {
if (!previous.task && current.task) {
var attachment = new GlideSysAttachment();
attachment.copy('interaction', current.sys_id, 'sn_customerservice_case', current.task.sys_id);
}
})(current, previous);
This checks that the case was just linked and then copies attachments from the interaction to the case.
If you're still not seeing the rule trigger, check the following:
Is the task field actually being set during the update?
Is the BR active and set to run "after update"?
Are there attachments on the interaction?
Does the user running the action have access to both tables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 10:30 AM
You can trigger this script via a Flow Designer, Business Rule depending on your workflow
Option 1: Business Rule
Use this if you want the script to run automatically when a record is updated or inserted.
Steps:
- Go to System Definition > Business Rules.
- Click New.
- Fill in:
- Name: e.g., Copy Attachments to Case
- Table: Interaction (or your custom interaction table)
- When to run: after update or insert
- Condition: e.g., when a Case is linked or
current.case.changes() && current.case // assuming 'case' is a reference field
- In the Script field, paste the script and replace the sourceSysId and targetSysId with dynamic values like:
Option 2: Flow Designer
Use this if you prefer a low-code/no-code approach.
Steps:
- Go to Flow Designer.
- Create a new Flow:
- Trigger: Record created or updated on Interaction
- Condition: Case is linked or not empty
- Add an Action:
- Choose Script.
- Paste the script and use inputs to pass sourceSysId and targetSysId.
Script:
(function execute(inputs, outputs) {
var sourceTable = 'interaction'; // or 'sn_customerservice_case_interaction'
var targetTable = 'sn_customerservice_case';
var sourceSysId = 'SOURCE_INTERACTION_SYS_ID'; // Replace with actual Interaction sys_id
var targetSysId = 'TARGET_CASE_SYS_ID'; // Replace with actual Case sys_id
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', sourceTable);
attachmentGR.addQuery('table_sys_id', sourceSysId);
attachmentGR.query();
while (attachmentGR.next()) {
var sa = new GlideSysAttachment();
var attachmentData = sa.getBytes(attachmentGR);
sa.write(targetTable, targetSysId, attachmentGR.file_name.toString(), attachmentGR.content_type.toString(), attachmentData);
}
})();
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2025 07:32 PM
when case is created from interaction a record gets inserted into "interaction_related_record" table.
you should have after insert business rule on that table
(function executeRule(current, previous) {
var attachment = new GlideSysAttachment();
attachment.copy('interaction', current.interaction, 'sn_customerservice_case', current.task);
})(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
‎06-16-2025 09:29 PM
Hope you are doing good.
Did my reply answer your question?
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
‎06-13-2025 08:35 AM
Here's why your Business Rule is not working and how to fix it:
Business Rule not triggering
If the Business Rule is set on a related record table and that table is not being updated when the interaction is linked to a case, then the rule won't fire. Make sure the rule is set on the correct table and event. Use conditions like "after update" where current.task or current.case becomes populated.
No need to call attachment.update()
The method GlideSysAttachment.copy() already performs the copy. There is no need to call update(), and doing so can cause issues because attachment is not a GlideRecord—it is a helper class.
Correct usage of table names
Replace 'case table' with the exact table name of your case, such as sn_customerservice_case or sn_hr_core_case.
Updated example script:
This should go in an after update Business Rule on the interaction table, assuming the case reference (task) is being updated:
(function executeRule(current, previous) {
if (!previous.task && current.task) {
var attachment = new GlideSysAttachment();
attachment.copy('interaction', current.sys_id, 'sn_customerservice_case', current.task.sys_id);
}
})(current, previous);
This checks that the case was just linked and then copies attachments from the interaction to the case.
If you're still not seeing the rule trigger, check the following:
Is the task field actually being set during the update?
Is the BR active and set to run "after update"?
Are there attachments on the interaction?
Does the user running the action have access to both tables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2025 07:56 AM
@danmjunqueira Hey Hi !!
I have done all the mentioned things above, once case is created from the interaction. it is coming up in the related
But the BR is not getting triggered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 03:22 AM
@Roshnee Dash @Ankur Bawiskar @Roshnee Dash @Bert_c1 @danmjunqueira
Thanks everyone, for your response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 09:04 AM
when the file should be copied?
do you require when case is created from interaction?
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