Copy attachments but they are never shown in form

rbazua
Kilo Contributor

I am using the provided API for cloning the attachments from one record to another:

GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id');

My problem is, even if it appears the attachments are cloned correctly, the destination form never shows them.

I can see in the Notes and Activity Log when the attachments were copied.

Also, I can see the attachments in sys_attachment and sys_attachment_doc if I query them using the REST API.

If I manually upload an attachment directly in the destination record form, it appears normally.

I tested it with many users to test if it was a security problem, but no luck.

I have used this API function with other tables and it works like a charm.

Why wouldn't the attachments appear in the form if they exist in the tables?

Some screenshots:

Here is the log of the attachments being clones to the form by the API

Attachments01.JPG

But they doesn't appear on the form

Attachments02.JPG

Any help will be much appreciated.

2 REPLIES 2

henry_cheng
ServiceNow Employee
ServiceNow Employee

Hi Ricardo,



Firstly use below wiki page to check to see if you disabled attachment on this table.


https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/administer/form-administration/...


Then check to see if specific file extensions are restricted from your instance.


https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/administer/form-administration/...



If still does not work, please raise an incident in ServiceNow HI system then support team will have a further look.



Cheers


Henry


agriffin
Tera Contributor

Hi Ricardo, I just ran into this issue today because I was attempting to copy attachments from one record [x] to another record [y] where the [y] record was being referenced in record [x].



Since this reference field (which was just the parent field) was specified to reference the base 'task' table, the API was creating copies and associating them with the 'task' table, instead of the extended table I intended (which was the requested item table).



Because attachments show up based on the table, and the copied attachments were referencing the base table, these attachments wouldn't show up within the form of the extended table.



Here's what I used:



GlideSysAttachment.copy(tableName, gr.sys_id, parentTable, grParent.sys_id);



The variable 'parentTable' was set by getting the task type of my parent record (using the 'sys_class_name' column).



Hope this helps!