Reference

Endpoint Download Table Attachments By Parent Row Search


Name

download_attachments_by_parent_search

Description

Download attachments for parent rows returned by the parent query. When files are saved they are given a unique name using the pattern {table_sys_id}_{attachment_sys_id}_{attachment-file_name} so files with the same filename from different parent records will not overwrite each other in the download folder. [API reference]

Parameters

Parameter Required Options
Name: SaveFolder

Label: SaveFolder

Specify a disk folder path to save file(s) to (e.g. c:\temp)
YES
Name: PagingRowCount

Label: Page Size (Default=2000, Max=10000)

Max can be 10000 but it may decrease performance if you fetching less than 10K rows in some requests.
YES
Name: TableName

Label: TableName

Table name
YES
Name: OverwriteFile

Label: OverwriteFile

Option Value
True True
False False
Name: AttachmentQuery

Label: Attachment Filter / Order By

Server-side filter for sys_attachment (file name, size, type, date, parent record, etc.)
Option Value
Uploaded Today sys_created_on>=<>^sys_created_on<=<>
Uploaded Last 2 Days sys_created_on>=<>
Uploaded After Date sys_created_on>=2026-01-01
File Name Equals file_name=dump.png
File Name Starts With file_nameSTARTSWITHdump
File Name Contains file_nameLIKEerror
File Name Ends With file_nameENDSWITH.pdf
Images Only content_typeSTARTSWITHimage/
Larger Than 1MB size_bytes>1048576
Uploaded By User sys_created_by=admin
Order By Created Date ORDERBYsys_created_on
Order By Size Desc ORDERBYDESCsize_bytes
Name: PagingOffset

Label: PagingOffset

Name: SysId

Label: SysId

Row 'sys_id'
Name: Fields

Label: Fields to include in response (Keep blank to get all fields -OR- Enter comma separated list)

Comma-separated field names you want to return in the response. E.g. sys_id,name,label,sys_name,sys_updated_on. Using this setting reduces the response size and speed up the processing.
Name: Query

Label: Query / Order By (Server Side Filter)

Server-side encoded query for filtering and ordering records. Supports string, numeric, date, NULL checks, AND/OR logic, and ORDER BY clauses.
Option Value
Equals (String) name=Test
Equals (Number) priority=1
Not Equal state!=closed
AND Condition state=active^priority=1
OR Condition state=active^ORstate=pending
IN List stateINactive,pending,closed
NOT IN List stateNOT INactive,closed
Starts With nameSTARTSWITHTest
Ends With nameENDSWITH001
Contains (LIKE) short_descriptionLIKEerror
Does Not Contain short_descriptionNOT LIKEpassword
Greater Than (Number) priority>2
Less Than (Number) priority<4
Between Numbers priority>=2^priority<=4
Is Empty assigned_toISEMPTY
Is Not Empty assigned_toISNOTEMPTY
Created After Date sys_created_on>=2026-01-01
Created Before Date sys_created_on<=2026-01-31 23:59:59
Created Today sys_created_on>=<>^sys_created_on<=<>
Updated Last 2 Days sys_updated_on>=<>
Multiple Conditions Mixed state=active^priority>1^short_descriptionLIKEerror
Order By Column ORDERBYname
Order By Column Desc ORDERBYDESCsys_created_on
Order By Multiple Columns ORDERBYpriority^ORDERBYDESCsys_created_on
Filter + Order state=active^ORDERBYsys_updated_on

Output Columns

Label Data Type (SSIS) Data Type (SQL) Length Description
table_sys_id DT_STR varchar(32) 32 Parent Row Id (e.g. Incident, Problem)
sys_id DT_STR varchar(32) 32 Attachment Id
table_name DT_STR varchar(255) 255
file_name DT_WSTR nvarchar(255) 255
size_bytes DT_I8 bigint File size in bytes from sys_attachment table
content_type DT_WSTR nvarchar(255) 255 MIME type of the file (e.g. image/png, application/pdf) from sys_attachment table
hash DT_WSTR nvarchar(64) 64 File hash for integrity verification from sys_attachment table
sys_created_on DT_DBTIMESTAMP datetime When the attachment was created from sys_attachment table
sys_created_by DT_WSTR nvarchar(128) 128 User who created the attachment from sys_attachment table
saved_file_size DT_I8 bigint
status_code DT_I4 int
error_message DT_STR varchar(4000) 4000
save_folder DT_WSTR nvarchar(255) 255
data_bytes DT_IMAGE varbinary(0)
If the column you are looking for is missing, consider customizing ServiceNow Connector.

Input Columns

Label Data Type (SSIS) Data Type (SQL) Length Description
There are no Static columns defined for this endpoint. This endpoint detects columns dynamically at runtime.

Examples

SSIS

Use ServiceNow Connector in API Source or in API Destination SSIS Data Flow components to read or write data.

API Source

API Source - ServiceNow
Read and write ServiceNow data effortlessly. Integrate, manage, and automate incidents, tasks, attachments, and records — almost no coding required.
ServiceNow
Download Table Attachments By Parent Row Search
Required Parameters
SaveFolder Fill-in the parameter...
Optional Parameters
OverwriteFile True
ContinueOn404Error True
Attachment Filter / Order By
SSIS API Source - Read from table or endpoint

API Destination

API Destination - ServiceNow
Read and write ServiceNow data effortlessly. Integrate, manage, and automate incidents, tasks, attachments, and records — almost no coding required.
ServiceNow
Download Table Attachments By Parent Row Search
Required Parameters
SaveFolder Fill-in the parameter...
Optional Parameters
OverwriteFile True
ContinueOn404Error True
Attachment Filter / Order By
SSIS API Destination - Access table or endpoint

ODBC application

Use these SQL queries in your ODBC application data source:

Download Table Attachments By Parent Row Search

-- Download attachments for specific parent records (multiple parent IDs) to c:\temp (always overwrite)
SELECT * FROM download_attachments_by_parent_search
WITH(TableName='problem', Query='sys_idIN62304320731823002728660c4cf6a7e8,6632130c730123002728660c4cf6a734', SaveFolder='c:\temp', OverwriteFile='True')

-- Parent-level filter: problems updated in last 2 days; attachment-level filter: file name ends with .png or .zip; save to c:\temp (fail if file exists)
SELECT * FROM download_attachments_by_parent_search
WITH(
  TableName='problem',
  Query='sys_updated_on>=<<today-2d,FUN_TO_DATETIME>>',
  AttachmentQuery='file_nameENDSWITH.png^ORfile_nameENDSWITH.zip',
  SaveFolder='c:\temp',
  OverwriteFile='False'
)

-- Parent-level filter by sys_id and attachment filter by exact file name; save to c:\temp
SELECT * FROM download_attachments_by_parent_search
WITH(TableName='problem', Query='sys_id=62304320731823002728660c4cf6a7e8', AttachmentQuery='file_name=dump.png', SaveFolder='c:\temp', OverwriteFile='True')

-- Attachments larger than 1 MB for problems updated in the last month; save to c:\temp
SELECT * FROM download_attachments_by_parent_search
WITH(
  TableName='problem',
  Query='sys_updated_on>=<<today-1m,FUN_TO_DATETIME>>',
  AttachmentQuery='size_bytes>1048576',
  SaveFolder='c:\temp',
  OverwriteFile='True'
)

-- Only image attachments for a given parent; save to c:\temp (fail if file exists)
SELECT * FROM download_attachments_by_parent_search
WITH(TableName='problem', Query='sys_id=62304320731823002728660c4cf6a7e8', AttachmentQuery='content_typeSTARTSWITHimage/', SaveFolder='c:\temp', OverwriteFile='False')

SQL Server

Use these SQL queries in SQL Server after you create a data source in Data Gateway:

Download Table Attachments By Parent Row Search

DECLARE @MyQuery NVARCHAR(MAX) = '-- Download attachments for specific parent records (multiple parent IDs) to c:\temp (always overwrite)
SELECT * FROM download_attachments_by_parent_search
WITH(TableName=''problem'', Query=''sys_idIN62304320731823002728660c4cf6a7e8,6632130c730123002728660c4cf6a734'', SaveFolder=''c:\temp'', OverwriteFile=''True'')

-- Parent-level filter: problems updated in last 2 days; attachment-level filter: file name ends with .png or .zip; save to c:\temp (fail if file exists)
SELECT * FROM download_attachments_by_parent_search
WITH(
  TableName=''problem'',
  Query=''sys_updated_on>=<<today-2d,FUN_TO_DATETIME>>'',
  AttachmentQuery=''file_nameENDSWITH.png^ORfile_nameENDSWITH.zip'',
  SaveFolder=''c:\temp'',
  OverwriteFile=''False''
)

-- Parent-level filter by sys_id and attachment filter by exact file name; save to c:\temp
SELECT * FROM download_attachments_by_parent_search
WITH(TableName=''problem'', Query=''sys_id=62304320731823002728660c4cf6a7e8'', AttachmentQuery=''file_name=dump.png'', SaveFolder=''c:\temp'', OverwriteFile=''True'')

-- Attachments larger than 1 MB for problems updated in the last month; save to c:\temp
SELECT * FROM download_attachments_by_parent_search
WITH(
  TableName=''problem'',
  Query=''sys_updated_on>=<<today-1m,FUN_TO_DATETIME>>'',
  AttachmentQuery=''size_bytes>1048576'',
  SaveFolder=''c:\temp'',
  OverwriteFile=''True''
)

-- Only image attachments for a given parent; save to c:\temp (fail if file exists)
SELECT * FROM download_attachments_by_parent_search
WITH(TableName=''problem'', Query=''sys_id=62304320731823002728660c4cf6a7e8'', AttachmentQuery=''content_typeSTARTSWITHimage/'', SaveFolder=''c:\temp'', OverwriteFile=''False'')';

EXEC (@MyQuery) AT [LS_TO_SERVICENOW_IN_GATEWAY];