- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 09:50 AM - edited 07-31-2023 09:51 AM
Hi @Ankur Bawiskar ,
I need to update the attachment from record producer to the incident table form. I am seeing "ZZ_YY" prefix in the table name field on the sys_attachment" table. this is causing the error while executing the code.
Here is the code:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 07:43 AM
can you try this code?
I have commented this line
// new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id);
(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);
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
08-01-2023 05:56 AM
So the code I shared is working fine.
It will ensure there is only 1 record in sys_attachment and that too without the prefix since we are updating the table name
Could you please share screenshots?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 06:45 AM
Attached is the screenshot for your reference.
Two records have been created, one with ZZ_YY prefix and the other without prefix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 07:43 AM
can you try this code?
I have commented this line
// new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id);
(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);
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
08-02-2023 02:30 AM
don't know for what reason, I'm still getting the duplicate entries in sys_attachment table. However, this code has helped me in the implementation.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 08:39 AM
Hi @Ankur Bawiskar - Do you know why this line of code is removed 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