Processing XML Import via Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 01:18 PM
Is there a way to process an XML import file via script rather than GUI? Instead of going to "Import XML" have a script that pulls the file by location or content and processes it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 03:42 PM
Depending upon what is needed the basic way is to use a data source.
Setting the "Type" field as "File" or "Custom script".
- With File type the system will parse the data based on the "Format" field and "XPath for each row" field.
- "Format" field set to "XML"
- "XPath for each row" field set with the xpath to indicate what are the list of records. For example if you had an unload XML of a list of exported incidents the XPath might be something like "/unload/incident"
- With the Custom script type you would write a script to do the parsing and fetching
There is also a field called "File retrieval method" which indicates how the file gets pulled which can be from an attachment (attached to the data source record) or various protocol methods like FTP, SFTP, HTTPS etc.
This would work great for updating existing records.
The tricky part is if you're also expecting to import new records (such as moving data from instance to another instance). There will be some extra work for system fields such as keeping the "sys_created_on" dates and things of the a nature as well as comments and they're original created and user info.
Another possibility is to use a combination of the data source with Type Custom script and a Table REST API.
In the Data Source's Custom script parse the through the XML (leverage the XMLDocumentV2 API) and then point to the Table REST API to either update/create records based on the data.
XMLDocumentV2: https://developer.servicenow.com/dev.do#!/reference/api/utah/server/no-namespace/c_XMLDocument2Scope...
Table API: https://developer.servicenow.com/dev.do#!/reference/api/utah/rest/c_TableAPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 12:06 AM - edited 06-12-2025 12:09 AM
Yes, you can make an HTTP POST request to the sys_upload.do endpoint using an admin-level API account. Be sure to include the necessary HTTP request parameters, which you can observe in the network activity log when manually uploading the XML file through the UI.
Make sure to include HTTP session data along with the auth-creds in the post request.