Attachment not being transferred from record producer to HR ticket

samirmeroua
Tera Contributor

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?

 

5 REPLIES 5

samirmeroua
Tera Contributor
 

Tanushree Maiti
Tera Sage

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);

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@samirmeroua 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

PradeepReddyA
Tera Contributor

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 

 

var grAttachment = new GlideRecord('sys_attachment');
if(grAttachment.get(producer.backend_name)){ //attachment field name
grAttachment.setValue("table_name", 'hrtablename');
grAttachment.update();
 
}
Hope that Helps!