Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

saveAttachment()

Arnab2
Kilo Contributor

Hi everyone,

The saveAttchment ('table_name','sys_id of record') function will allow us to attach a document to a record.

Can anyone tell me where to locate this function and how it works??

Regards,

Arnab

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Arnab,



It's built in to one of the client script libraries that gets sent to the the browser when your page is loaded. I see it mentioned only in two places in the system.


  • A UI action called New
  • A UI page called assessment_take2


It is not documented in the API info on the developer site nor does it appear to be editable/viewable by admins.


Thanks Chuck,



Is there a way to call this function server side?



Regards,


Arnab


I believe it is possible to find the attachment record you create with this function by querying sys_attachment GR limited to table_name and table_sys_id entered as params while calling saveAttachment()

 

It works even for the table_sys_id which does not exists, I am going to (ab)use it in my UI action available in the list allowing users to add attachment to selected records

  • for each such request I will create new fake_table_sys_id and let SN save attachment for it
  • then I will send the fake_table_sys_id via GlideAjax to the server together with list of sys_ids of selected records
  • there I will iterate over the selected sys_ids and copy attachment identified by its fake_table_sys_id to all of them using GlideSysAttachment.copy(table_name, fake_table_sys_id, target_table_name, sys_id_from_selected)