Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Attachment variable on record producer not getting added as attachment on incident created

ritaaudi
Tera Contributor

Hi:

I created an attachment variable on a record producer. It seems that when the user adds the attachment and submits the form, it is not getting attached to the incident record created by the record producer. I see it creates the highlighted as example but does not get attached to the incident record.

find_real_file.png

 

Please advise.

Thank you, Rita

1 ACCEPTED SOLUTION

 

You can use following script in record producer script section to attach the attachment to current record, you can update it accordingly 

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.attachment)){ //attachment field name
	gr.table_name='incident';     //copy to table name
	gr.table_sys_id=current.sys_id;//copy to record sys_id
	gr.insert();
	
}

View solution in original post

14 REPLIES 14

Pranesh072
Mega Sage

You have to create a new field as file attachment and map the record producer attachment variable to it.

 

  • In a record producer, when the variable is mapped to a task table field. This variable can be mapped only to the File Attachment field type of a task table.

find_real_file.png

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/product/service-catalog-management...

ritaaudi
Tera Contributor

Hi:

But I don't want to create a custom field on INC. I want it to attach to the existing attachment on INC, like this:

find_real_file.png

 

 

You can use following script in record producer script section to attach the attachment to current record, you can update it accordingly 

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.attachment)){ //attachment field name
	gr.table_name='incident';     //copy to table name
	gr.table_sys_id=current.sys_id;//copy to record sys_id
	gr.insert();
	
}

Jack9
Giga Contributor

Although this works, it would be better to use gr.update(); instead of gr.insert();

That way you simply point the existing attachment to the proper record instead of making a copy