Attach files to a record dynamically

Naga jyothi sri
Tera Contributor

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.

2 REPLIES 2

Weird
Mega Sage

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);

 

GlideSysAttachment - Global (servicenow.com)

Thank you for your response. I'll try that