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:
Label: SaveFolder Specify a disk folder path to save file(s) to (e.g. c:\temp) |
YES | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
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:
Label: TableName Table name |
YES | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: OverwriteFile |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: Attachment Filter / Order By Server-side filter for sys_attachment (file name, size, type, date, parent record, etc.) |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: PagingOffset |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
Label: SysId Row 'sys_id' |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Name:
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:
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. |
|
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)
|
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
| Required Parameters | |
|---|---|
| SaveFolder | Fill-in the parameter... |
| Optional Parameters | |
| OverwriteFile | True |
| ContinueOn404Error | True |
| Attachment Filter / Order By | |
API Destination
| Required Parameters | |
|---|---|
| SaveFolder | Fill-in the parameter... |
| Optional Parameters | |
| OverwriteFile | True |
| ContinueOn404Error | True |
| Attachment Filter / Order By | |
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];