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.

How to attach file from a local machine to a particular record.

Vishal_Jaiswal
Mega Guru

My local machine folder(Documents) has a list of attachments with different types like PDF, JPG, etc.

The attachment file name starts with incidentNumber_fileName. For example: INC123456_users.pdf.

Requirement: I have to attach these attachments to their corresponding incident. How to do this?

14 REPLIES 14

Bhimashankar H
Mega Sage

Hey @Vishal_Jaiswal ,

 

You can do it by data import. Refer to below post which explain it by step by step: 

Create a new data source by navigating to System Import Sets > Data Sources and clicking on New. Fill in the necessary details such as Name, Table Name, and File Extension.

Bult Upload Attachment - Community ,

 

You can upload attachment using API methods as well via REST. It requires tool like powershell or windows batch scripting for more detailed explanation follow the below.

pathwayscg.com/loading-attachments-to-servicenow-from-a-local-machine-via-batch-scripting-in-windows/

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

J Siva
Kilo Patron
Kilo Patron

Hi @Vishal_Jaiswal 
I don't think it's possible to pick a file directly from your local machine using a script. However, you could try storing the file in one of your organization's shared paths and then use your MID server to retrieve the file from that shared location into the instance.
I've tried this, but you can give a try and see how it goes..
Regards,
Siva

Hi @J Siva ,

Can you please share the steps with code.

@Vishal_Jaiswal Check the below article to import files form Mid sevrer.
Automated Data Import - Using MID Server and PowerShell
Make sure that the file is stored in the Mid server host/shared path

ColtonsR
Tera Contributor

If your attachments are named with the incident number at the start, you could write a script (like in Python) to scan your folder, parse the incident number from each file name, then upload or attach the file to the matching incident in your system via its API or interface. depends on what system you’re using for incidents though, what platform is it.