
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 03:33 AM
Hi,
I have a 'attachment' type variable in my record producer which i have made mandatory. When the user uploads any attachment, i want the attachment to get saved in the record created. But instead, it is hiding it.
I can see the entry created in sys_attachment but under table name field, a prefix ZZ_YY is getting added which is making the attachment hidden.
Please find the field below -
Record in sys_attachment -
Can anyone help me get this attachment added in the record as it happens when add any attachment from here -
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 06:05 AM
This worked well for me
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().copy(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
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 04:26 AM
Hi,
so you want to copy it to the record
did you go through the 2nd link -> it mentions on copying the attachment variable
Copy attachment added via service catalog variable
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 05:23 AM
there it says if i have to copy from one record to another. How can i do from record producer to generated record?
My scenario - I have the attachment type variable in record producer and want the attachment in the header of the record created
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 05:33 AM
Hi,
can you try to use the script is shared in the 2nd link
- Use this alternative copy: new global.VariableUtil().(attachmentId, targetTable, targetId); which does NOT add ZZ_YY.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 06:05 AM
This worked well for me
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().copy(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
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 07:04 AM
It worked. Thanks.
Now i am trying to create a new record in another table through an after insert BR and tried to do something like below -
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_name',current.getTableName());
attachment.addQuery('table_sys_id',current.sys_id);
attachment.query();
if(attachment.next()){
gs.info("code working right ");
var gr = new GlideRecord('x_eyit2_bo_journal_entry_data_mapping');
gr.u_journal_header = current.sys_id;
gr.setValue('u_status','ready');
var newRecord = gr.insert();
new global.VariableUtil().copy(attachment.sys_id, gr.getTableName(),newRecord);
}
But doesn't seem to work. Can you help?