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

Joe72
Tera Contributor

Indeed! Save your instance from all the duplicate attachments and just update the existing one. Perhaps ServiceNow will fix this in a later release rather than having it disappear into the ether.

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.attachment)){ //your attachment variable
	gr.table_name='incident';     //update the table name
	gr.update();
}

Joe72
Tera Contributor

Indeed! Save your instance from all the duplicate attachments and just update the existing one.

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.attachment)){ //your attachment variable
	gr.table_name='incident';     //update the table name
	gr.update();
}

Hi, I tried the below code, the attachment table name is showing correctly i.e sc_req_item in sys_attachment.  but the attachment is either corrupt/showing a blank file. could you please help?

I tried different types of documents and doc sizes.

 

I've added this code in the record producer script part:

 

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

ritaaudi
Tera Contributor

Awesome! That worked! Thank you!!

Robert Smith
Tera Expert

I came across this post while looking for the same answer and it pointed me in the right direction. I was able to modify this slightly and use the same attachment record that was previously saved in the sys_attachments table. Hope this helps someone, please see below. 

var gr = new GlideRecord('sys_attachment');
    if (gr.get(producer.attachment_variable_name)) {
        gr.table_name = current.sys_class_name;
        gr.update();
    }