Attach files to a record dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 09:46 PM
Hi,
How to attach external files to a record dynamically?
while creating a record from service portal to ServiceNow table, is it possible to attach a file dynamically in service portal widget code and show it table when record is created. if yes, what is the process?
I have tried with some reference codes, it is creating a new record but not showing any added attachments. I checked in the attachments table too, its not displaying anything.
Can anyone help me on this.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 11:25 PM
Assuming you're copying the attachment from somewhere else (like KB article):
var attachment = new GlideSysAttachment();
attachment.copy('source_table', 'sys_id', 'target_table', 'sys_id');
So basically when you've inserted your record you'd then want to copy the attachment on it.
For example on a gr.insert():
var sysID = gr.insert();
var attachment = new GlideSysAttachment();
attachment.copy('kb_knowledge', 'knowledge_sys_id', 'gr_table', sysID);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 11:29 PM
Thank you for your response. I'll try that