- 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
07-31-2023 10:06 AM
Hi there,
What type of variable is producer.number_list? If I look at your description, this is a string? When performing a .get in the way you are doing now, it should be a sys_id instead.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 10:07 AM
Hi @Nishant26,
Try this script,
var gr = new GlideRecord('sys_attachment');
if(gr.get("producer.number_list")){ //attachment field name
gr.table_name= gr.table_name.replace('ZZ_YY','');
gr.table_sys_id=current.sys_id;
gr.update();
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
Regards,
T Mohan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 11:19 PM
I have tried the script but still not getting the result, I am unable to copy the attachment from the record producer's attachment variable to Incident table record on the which the record producer is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 08:25 PM
what is your business requirement?
If you are having a attachment type variable then it shows ZZ_YY prefix when you attach file to that variable. It's platform behavior.
Are you saying you want to copy that file to the record which gets generated from record producer?
I shared solution few years ago for this; refer this link
Disable ZZ_YY prefix from attachment when added through record producer
Sharing script here as well
1) I created Async After Insert BR on the target table
2) Script as this
a) Remove the ZZ_YY
b) Then use the Copy Attachment
(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);
Output:
1) The file added to the record
2) The file present on the attachment variable
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