Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Copy custom variable in record producer to OOTB record producer attachment

ronro2
Tera Contributor

Hey! 

In a record producer I have a custom variable of type attachment called 'bifoga_fil':

ronro2_0-1777024047068.png



So I want to copy this to the OOTB attachment on the record producer in the back-end, so that the attachment is visible in the banner above and in the logs. 

ronro2_0-1777023445003.png


I've marked what I mean with red. 

So, I am thinking an after insert business rule of some kind? What would that look like? 

I'm thankful for your help. 

All good, 

1 ACCEPTED SOLUTION

@ronro2 

the file should get attached to the record if you used the record producer script

💡 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

View solution in original post

29 REPLIES 29

@Ankur Bawiskar the issue is that it doesn't show in the background as an attachment in the logs and in the banner above. Because it is not mapped to the OOTB sys_attachment? I guess. 

Or am I missing your point? 

@ronro2 

yes you missed my point

1) have attachment variable and make it mandatory based on your condition

2) then use this script in record producer script and then that file attached on variable will be copied to the target record on record header

new global.VariableUtil().copyAttachment(producer.<variableName>,'<tableName>', 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

@ronro2 

Any update to above?

I already shared a working solution

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

Rakesh_M
Kilo Sage

Hi @ronro2 ,
Add the following script to script field of record producer

var attach_sysid = producer.bifoga_fil; //variable_name

if (attach_sysid) {
    var gr = new GlideRecord("sys_attachment");
    if (gr.get(attach_sysid)) {
        gr.table_sys_id = current.sys_id;  
        gr.table_name = "incident";   //replace with table name
        gr.update();
    }
}

Screenshot 2026-04-24 at 7.07.42 PM.png

ronro2
Tera Contributor

@Rakesh_M so, I get this error message when I submit the form with an attachment: 

'Write operation against 'sys_attachment' from scope 'x_vgll_rail' has been refused due to the table's cross-scope access policy'. 

So they are in different scopes, is there a way to work through this in the script? To get cross scope access?