Follow-up question - Remove prefix from table name in sys_attachment table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 09:21 AM
Hi @Ankur Bawiskar.
This is just a follow-up question regarding the script below you posted in https://www.servicenow.com/community/itsm-forum/remove-prefix-from-table-name-in-sys-attachment-tabl.... You asked me to created a new post since this was an old thread.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
gr.addQuery("table_sys_id", current.sys_id);
gr.query();
if (gr.next()) {
gr.table_name = current.getTableName();
gr.update();
// new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id);
}
})(current, previous);
Do you know why this line of code is commented for "sc_req_item" table and the attachments still show up on attachment list on top of the record whereas the same line of code needs to be added for "sn_hr_core_case" table for the same reason? Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 08:05 PM
the commented code was possibly used to avoid duplicate file.
check this link where I shared solution on how to copy file from attachment type variable to target record on form
Disable ZZ_YY prefix from attachment when added through record producer
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
07-22-2025 07:27 AM
@Ankur Bawiskar - That's correct. But why is it duplicated on "sc_req_item" table and not on "sn_hr_core_case" table with the commented code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 07:34 AM
when I shared the earlier solution and when I wrote the blog recently, it didn't duplicate the file on target record
check this blog
Copying Attachments from a Record Producer's Attachment Variable to a Target Record in ServiceNow
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
07-23-2025 04:19 PM
Hi @Ankur Bawiskar - Thanks for sharing another way to copy the attachment in above post. I disabled the Business Rule and tried this record producer script on "sn_hr_core_case_relations" table, which is extended from "sn_hr_core_case", but it still shows duplicate copies of the attachment under Activity stream as seen in the attached screenshot.