- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 03:39 AM
Hi Experts,
I had a use case where I had to copy attachment from one table to another table so I used the script below.
var attachment = new GlideSysAttachment();
var attached = attachment.copy('source_table','source_table_sys_id', 'sys_data_source','datasource_sys_id' );
now that I have to copy an attachment from field on a custom table(file attachment type) to data source, the above script doesnt work as expected. the table name in sys_attachment appears as ZZ_YY appended by custom table name. Im not even able to copy field attachment to the same form.
any responses are highly appreciated
regards,
Ubada Barmawar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2024 03:35 AM - edited 04-21-2024 03:45 AM
Hi @Ubada Barmawar ,
What you have attempted is right yes need to created a business rule on change of attachment field you need to take the table name and sys_id of the attachment and copy it on target table using attachment.copy.
From the field which has attachement get the name of the file and do a glide record on sys_attachment table once the record attachment is found in query initialize the attachment on the target table were you needed it..
here is the sample code :
var gr = new GlideRecord('xxxx');
gr.get('f847adac1b40d110be52419fe54bcbca');
var fSys = gr.u_current_file.toString();
gs.info("File sys id: " + fSys);
var gAtach = new GlideRecord('sys_attachment');
gAtach.get(fSys);
gs.info("File Name:" + gAtach.file_name);
var targetRef = new GlideRecord('your_table');
targetRef.get('target_sys_id');
//Example of script
var glideSysAttachmentRef = new GlideSysAttachment();
var guid = "";
var newFileName = gAtach.getValue("file_name");
guid = glideSysAttachmentRef.writeContentStream(targetRef, newFileName, gAtach.getValue("content_type"), glideSysAttachmentRef.getContentStream(gAtach.getUniqueValue()));
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 03:54 AM
Try the flow action 'copy attachment'. You can just give the source and the target and it will copy it for you.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 04:03 AM
copy attachment takes attachment from record and not from field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 03:55 AM - edited 04-05-2024 08:16 AM
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 04:10 AM - edited 04-08-2024 12:18 PM
This code is AI generated and it doesn't work!