Reference

Endpoint Get Attachments By Parent Row Search


Name

get_attachments_by_parent_search

Description

Get table rows [API reference]

Parameters

Parameter Required Options
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: 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
sys_id DT_WSTR nvarchar(32) 32
table_sys_id DT_WSTR nvarchar(32) 32
file_name DT_WSTR nvarchar(512) 512
content_type DT_WSTR nvarchar(255) 255
hash DT_WSTR nvarchar(64) 64
state DT_WSTR nvarchar(50) 50
size_bytes DT_I8 bigint
size_compressed DT_I8 bigint
chunk_size_bytes DT_I8 bigint
image_width DT_I4 int
image_height DT_I4 int
average_image_color DT_WSTR nvarchar(16) 16
compressed DT_BOOL bit
table_name DT_WSTR nvarchar(80) 80
sys_created_by DT_WSTR nvarchar(128) 128
sys_updated_by DT_WSTR nvarchar(128) 128
sys_tags DT_WSTR nvarchar(1024) 1024
sys_created_on DT_DBTIMESTAMP datetime
sys_updated_on DT_DBTIMESTAMP datetime
sys_mod_count DT_I4 int
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
Get Attachments By Parent Row Search
Optional Parameters
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
Get Attachments By Parent Row Search
Optional Parameters
Attachment Filter / Order By
SSIS API Destination - Access table or endpoint

ODBC application

Use these SQL queries in your ODBC application data source:

Get Attachments By Parent Row Search

-- Find attachments for specific parent records (multiple parent IDs)
SELECT * FROM get_attachments_by_parent_search
WITH(TableName='problem', Query='sys_idIN62304320731823002728660c4cf6a7e8,6632130c730123002728660c4cf6a734')

-- Parent-level filter: problems updated in last 2 days; attachment-level filter: file name ends with .png or .zip
SELECT * FROM get_attachments_by_parent_search
WITH(
  TableName='problem',
  Query='sys_updated_on>=<<today-2d,FUN_TO_DATETIME>>',
  AttachmentQuery='file_nameENDSWITH.png^ORfile_nameENDSWITH.zip'
)

-- Parent-level filter by sys_id and attachment filter by exact file name
SELECT * FROM get_attachments_by_parent_search
WITH(TableName='problem', Query='sys_id=62304320731823002728660c4cf6a7e8', AttachmentQuery='file_name=dump.png')

-- Attachments uploaded by a specific user for parents matched by parent query
SELECT * FROM get_attachments_by_parent_search
WITH(TableName='incident', Query='opened_by=jsmith', AttachmentQuery='sys_created_by=jsmith')

-- Attachments larger than 1 MB for problems updated in the last month
SELECT * FROM get_attachments_by_parent_search
WITH(
  TableName='problem',
  Query='sys_updated_on>=<<today-1m,FUN_TO_DATETIME>>',
  AttachmentQuery='size_bytes>1048576'
)

-- Only image attachments (content type starts with "image/") for a given parent
SELECT * FROM get_attachments_by_parent_search
WITH(TableName='problem', Query='sys_id=62304320731823002728660c4cf6a7e8', AttachmentQuery='content_typeSTARTSWITHimage/')

-- Order attachments by creation date (per-parent results ordered by attachment date)
SELECT * FROM get_attachments_by_parent_search
WITH(TableName='problem', Query='sys_updated_on>=<<today-2d,FUN_TO_DATETIME>>', AttachmentQuery='ORDERBYsys_created_on')

-- Combine parent IN-list and attachment name contains filter
SELECT * FROM get_attachments_by_parent_search
WITH(
  TableName='problem',
  Query='sys_idIN62304320731823002728660c4cf6a7e8,6632130c730123002728660c4cf6a734',
  AttachmentQuery='file_nameLIKEerror'
)

SQL Server

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

Get Attachments By Parent Row Search

DECLARE @MyQuery NVARCHAR(MAX) = '-- Find attachments for specific parent records (multiple parent IDs)
SELECT * FROM get_attachments_by_parent_search
WITH(TableName=''problem'', Query=''sys_idIN62304320731823002728660c4cf6a7e8,6632130c730123002728660c4cf6a734'')

-- Parent-level filter: problems updated in last 2 days; attachment-level filter: file name ends with .png or .zip
SELECT * FROM get_attachments_by_parent_search
WITH(
  TableName=''problem'',
  Query=''sys_updated_on>=<<today-2d,FUN_TO_DATETIME>>'',
  AttachmentQuery=''file_nameENDSWITH.png^ORfile_nameENDSWITH.zip''
)

-- Parent-level filter by sys_id and attachment filter by exact file name
SELECT * FROM get_attachments_by_parent_search
WITH(TableName=''problem'', Query=''sys_id=62304320731823002728660c4cf6a7e8'', AttachmentQuery=''file_name=dump.png'')

-- Attachments uploaded by a specific user for parents matched by parent query
SELECT * FROM get_attachments_by_parent_search
WITH(TableName=''incident'', Query=''opened_by=jsmith'', AttachmentQuery=''sys_created_by=jsmith'')

-- Attachments larger than 1 MB for problems updated in the last month
SELECT * FROM get_attachments_by_parent_search
WITH(
  TableName=''problem'',
  Query=''sys_updated_on>=<<today-1m,FUN_TO_DATETIME>>'',
  AttachmentQuery=''size_bytes>1048576''
)

-- Only image attachments (content type starts with "image/") for a given parent
SELECT * FROM get_attachments_by_parent_search
WITH(TableName=''problem'', Query=''sys_id=62304320731823002728660c4cf6a7e8'', AttachmentQuery=''content_typeSTARTSWITHimage/'')

-- Order attachments by creation date (per-parent results ordered by attachment date)
SELECT * FROM get_attachments_by_parent_search
WITH(TableName=''problem'', Query=''sys_updated_on>=<<today-2d,FUN_TO_DATETIME>>'', AttachmentQuery=''ORDERBYsys_created_on'')

-- Combine parent IN-list and attachment name contains filter
SELECT * FROM get_attachments_by_parent_search
WITH(
  TableName=''problem'',
  Query=''sys_idIN62304320731823002728660c4cf6a7e8,6632130c730123002728660c4cf6a734'',
  AttachmentQuery=''file_nameLIKEerror''
)';

EXEC (@MyQuery) AT [LS_TO_SERVICENOW_IN_GATEWAY];