- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2026 09:10 PM
Hello All,
I have created a record producer and added the variable " Attachment" (gave it a different name),
When users upload the attachment, it is being copied to the HR case being created, any advise?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2026 12:55 AM
hey @samirmeroua
Option 1: Prevent attachment usage in Record Producer
Script
(function executeProducer(producer, current) {
current.short_description = producer.short_description;
current.description = producer.description;
current.opened_for = gs.getUserID();
if (producer.please_attach_the_l_and_l_roster) {
delete producer.please_attach_the_l_and_l_roster;
}
if (!producer.short_description) {
gs.addErrorMessage('Short description is mandatory');
current.setAbortAction(true);
return;
}
gs.info('HR Case being created for user: ' + gs.getUserName());
})(producer, current);
Option 2: Delete attachments after HR Case creation (Recommended)
Allow users to upload, but remove attachments once the HR Case is created.
Business Rule Configuration
Table: sn_hr_core_case After insert
Script
(function executeRule(current, previous /*null when async*/) {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', 'sn_hr_core_case');
att.addQuery('table_sys_id', current.sys_id);
att.query();
while (att.next()) {
att.deleteRecord();
}
})();
Option 3: Conditional control (Delete only in specific cases)
If attachments should be allowed only in certain scenarios:
Script (with condition)
(function executeRule(current, previous /*null when async*/) {
if (current.u_allow_attachment == false) {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', 'sn_hr_core_case');
att.addQuery('table_sys_id', current.sys_id);
att.query();
while (att.next()) {
att.deleteRecord();
}
}
})();
*************************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2026 09:11 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2026 09:59 PM - edited 03-25-2026 10:04 PM
Have you used a Before/Async Insert Business Rule to copy attachments from record producer to the HR case record.
If not , please create it.
Refer : KB2657281 Attachment Type Variable Does Not Add Files to Target Record in Record Producer
Cause
This is the default platform behavior: attachments uploaded via an Attachment Type variable in a Record Producer are not automatically copied to the target record. By design, these files are linked to the submission record, and additional configuration is required to transfer them to the generated record.
Resolution
1. Recognize that out-of-the-box, attachments from Attachment Type variables in Record Producers do not transfer to the target record.
2. Use a script or business rule to copy attachments from the submission record to the target record after the record is created.
For sample code:
(function executeRule(current, previous /*null when async*/) {
if (current.table_name == 'sc_re_item') { // <add your table name>
var rec = new GlideRecord('sys_attachment');
rec.addQuery('table_sys_id', current.table_sys_id);
rec.query();
while(rec.next()){
rec.table_name = 'sn_hr_core_case'; // Target HR Case Table rec.table_sys_id = producer.sys_id; rec.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2026 11:32 PM
OOTB the attachment won't be copied from attachment variable to target Record
you need to add script in record producer script to handle this
I created blog for this, check and enhance
Copying Attachments from a Record Producer's Attachment Variable to a Target Record in ServiceNow
In record producer script add this at the last
new global.VariableUtil().copyAttachment(producer.<variableName>,'<yourTargetTableName>', current.sys_id);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2026 11:46 PM
Hi @samirmeroua
You can use producer.variable_name(backend of the attachment variable) to access the backend value of the attachment variable in the Record Producer script.
Try this script
