- 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
‎02-07-2022 09:01 AM
Does not work.
"GlideSysAttachment.copy will always cause the new copy to have a table name starts with ZZ_YY for attachments variables, which according to this KB0868420"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 07:28 AM
It basically just updates the reference on the sys_attachment table to point to the table you want the attachment to live on, by directly manipulating the record.
For Example:
I created a record producer that points to the Incident table and a client script that logs the newValue parameter in an OnChange client script for My Attachment.
Note the sys_id in the console.
I can then go to the sys_attachment(s) table and see that this is available to me by this filter seen in the image below. Also, correct about the Table Name using ZZ_YY.
After submitting the Record producer, you can refresh the Attachments [ sys_attachment ] table to see the Table Name field has now been updated to the table name your Record Producer is pointed to. Note the Table Sys ID field is the sys_id of the incident my example has just created, so nothing to do here just more information for future decisions if needed.
Here is the example of my code in the Record Producer.
As you can see all it is doing is calling the record from the sys_attachment table directly and updating the Table Name reference.
I've not ran into any problems with this solution so far, but if someone notices something in the community reading this post please add to it so we can make the community stronger.
Thanks for reading.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2023 08:03 PM
This is poor logic, if there is an attachment file with the same name that already exists. It's possible for multiple users to upload identical files. Better to use an After Business Rule on the record producer table to find the attachment via the table_sys_id and update the table_name via glideRecord update. Also, what would you do if there are multiple attachments? Here's an example of a script include, and it's working well for me.
var AssociateCaseAttachment = Class.create();
AssociateCaseAttachment.prototype = {
initialize: function() {},
updateCaseAttachment: function(sys_id) {
if (!sys_id) {
return;
}
var grAttach = new GlideRecord('sys_attachment');
grAttach.setLimit(10);
grAttach.addEncodedQuery('table_sys_id=' + sys_id);
grAttach.query();
while (grAttach.next()) {
grAttach.table_name = 'YOUR Table NAME';
grAttach.update();
}
},
type: 'AssociateCaseAttachment'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2023 06:05 AM - edited ‎03-30-2023 06:15 AM
Hello Brian, this use case was for an attachment field on a record producer. When an attachment is uploaded to SN, it gives it the generic table name and the predefined sys_id for the record to be created from the SC Catalog Item widget. On submission of the form, you can use the sys_id of the attachment (captured in the attachment field) to look distinctly at that record and just point it to the table you are submitting the form too. There wasn't a need to look for multiple attachments since we are using the primary ID for the table. Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2023 05:09 AM
Hi, I tried below code for this case, the attachment table name is showing correctly i.e sc_req_item in sys_attachment. but the attachment is either corrupt/showing blank file. could you please help?
I've added this code in record producer script part:
var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.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();
}