how to get the file attachment which is generated as pdf from another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 07:09 AM
I have a table "AA" which is having a file attachment in pdf and the pdf file is not under any field which is just generated pdf in another business rule and put on the header of the record. so now I want to make this pdf file to use again in another "BB" table that is why I created a new field in "BB" table which is a file attachment type and Display name generated pdf . so I need to do that the "generated pdf " field hold the pdf generated from table "AA" record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 07:37 AM
Hi,
find the record in sys_attachment table that has 'table_name' = to AA and table_sys_id for the specific record in AA, and create a new record there for the record in table BB (requires the sys_id of the BB table record). Then find the records in sys_attachment_doc table for the existing sys_attachment record and create new records from those with the sys_attachment field set to the new record created in the sys_attachment table.
Anyway, attachments are stored in the sys_attachment table (metadata) and file chunks in the sys_attachment_doc table.
You can script that in a UI Action, or a background script. But you don't include details on when you want to do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 09:33 AM
There is a GlideSysAttachment API that does what I proposed. It is documented here:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 09:43 AM
Hi Meroda,
Attachments in ServiceNow are stored on the sys_attachment table. All attachments have a one-to-one relationship with the record to which they are attached.
In the case that you would like an attachment to be replicated onto another record, you would have to write a script to copy the document to the new record.
Here's an example script from the Developer API for GlideSysAttachment using the .copy() method:
var attachment = new GlideSysAttachment();
var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
var incGR = new GlideRecord('incident');
incGR.get(incidentSysID);
var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));
gs.info('Copied attachments: ' + copiedAttachments);