- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 09:20 AM
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.
Please advise.
Thank you, Rita
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 11:04 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2021 01:24 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2021 01:26 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 04:22 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 12:29 PM
Awesome! That worked! Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2021 06:49 AM
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();
}