ServiceNow Connector for Alteryx : Get attachments by parent row search via SQL
Learn how to get attachments by parent row search using the ServiceNow Connector for Alteryx. This connector enables you to read and write ServiceNow data effortlessly. Integrate, manage, and automate incidents, tasks, attachments, and records — almost no coding required. We'll walk you through the exact setup.
Let's dive in!
Create data source using ServiceNow ODBC Driver
-
Download and install ODBC PowerPack (if you haven't already).
-
Search for
odbcand open the ODBC Data Sources (64-bit):
-
Create a User data source (User DSN) based on the ZappySys API Driver driver:
ZappySys API Driver
- Create and use a User DSN if the client application runs under a User Account. This is the ideal option at design time (e.g., when developing in Visual Studio). Use it for both types of applications (64-bit and 32-bit).
- Create and use a System DSN if the client application runs under a System Account (e.g., as a Windows Service). This is usually the required option in a production environment. If your Windows Service is a 32-bit application, you must use the 32-bit ODBC Data Source Administrator to configure this
-
When the Configuration window appears give your data source a name if you haven't done that already, then select "ServiceNow" from the list of Popular Connectors. If "ServiceNow" is not present in the list, then click "Search Online" and download it. Then set the path to the location where you downloaded it. Finally, click Continue >> to proceed with configuring the DSN:
ServicenowDSNServiceNow
-
Now it's time to configure the Connection Manager. Select Authentication Type, e.g. Token Authentication. Then select API Base URL (in most cases, the default one is the right one). More info is available in the Authentication section.
ServiceNow authentication
Authenticate using ServiceNow instance username and password.
Locate your ServiceNow instance credentials and use them for HTTP authentication:
- Go to https://developer.servicenow.com/dev.do and log in.
- Click on your profile picture.
-
When a menu appears, click on Manage instance password or a similar option:
-
In a new window you will see your HTTP Basic Authentication credentials:
-
Done! Use this username and password when configuring HTTP Authentication parameters.
API Connection Manager configuration
Just perform these simple steps to finish authentication configuration:
-
Set Authentication Type to
Basic Auth (UserName and Password) [Http] - Optional step. Modify API Base URL if needed (in most cases default will work).
- Fill in all the required parameters and set optional parameters if needed.
- Finally, hit OK button:
ServicenowDSNServiceNowBasic Auth (UserName and Password) [Http]https://[$InstanceName$].service-now.com/api/nowRequired Parameters InstanceName (e.g. mycompany) Fill-in the parameter... User name Fill-in the parameter... Password Fill-in the parameter... Optional Parameters ApiVersion v2 RetryMode RetryWhenStatusCodeMatch RetryStatusCodeList 429 RetryCountMax 5 RetryMultiplyWaitTime True Date Time Value Handling
ServiceNow authentication
Authenticate using OAuth 2.0 Authorization Code Flow (3-legged)
Create OAuth application and use it for authentication:
- Login to your instance at https://your-instance-id.service-now.com.
-
Start by clicking on menu item All, then search for oauth, and click Application Registry option:
-
Then click button New:
-
Continue by clicking Create an OAuth API endpoint for external clients option:
-
Move on by naming your OAuth application and entering a Client Secret (or let it be generated automatically).
- Click on the lock icon next to the Redirect URL. Enter
https://zappysys.com/oauth. This is not needed if you use Client Credentials Grant or Password Grant -
Finally give it a final touch by increasing the Refresh Token Lifespan value to
315,360,000(it should last for 10 years):
- Change Default Grant Type as per your need. NOTE: If you prefer to use Client Credentials grant (Service account style access without using real userid-password) then your admin must enable it. Client Credentials is only supported on instances where it is explicitly enabled by the ServiceNow administrator. Its not supported in Dev / Free instance.
-
Done! Now you can use Client ID and Client Secret when configuring OAuth Authentication parameters.
Enable Client Credentials Grant Type
-
Enable the Client Credentials Grant Type:
Go to System Properties > All Properties, create a new property named
glide.oauth.inbound.client.credential.grant_type.enabled, and set it to true. - Configure the OAuth Application: Navigate to System OAuth > Application Registry, click New, and select Create an OAuth API endpoint for external clients. Set the name and save the record. In the Default Grant Type field, select Client Credentials and associate it with the integration user.
API Connection Manager configuration
Just perform these simple steps to finish authentication configuration:
-
Set Authentication Type to
OAuth Authorization Code Grant (User Creds) [OAuth] - Optional step. Modify API Base URL if needed (in most cases default will work).
- Fill in all the required parameters and set optional parameters if needed.
- Press Generate Token button to generate the tokens.
- Finally, hit OK button:
ServicenowDSNServiceNowOAuth Authorization Code Grant (User Creds) [OAuth]https://[$InstanceName$].service-now.com/api/nowRequired Parameters Redirect URI (***Must match as App Registry Page***) Fill-in the parameter...
ServiceNow authentication
Authenticate using OAuth Client Credentials Grant (Client ID and Client Secret). [API reference]
Create OAuth application and use it for authentication:
- Login to your instance at https://your-instance-id.service-now.com.
-
Start by clicking on menu item All, then search for oauth, and click Application Registry option:
-
Then click button New:
-
Continue by clicking Create an OAuth API endpoint for external clients option:
-
Move on by naming your OAuth application and entering a Client Secret (or let it be generated automatically).
- Click on the lock icon next to the Redirect URL. Enter
https://zappysys.com/oauth. This is not needed if you use Client Credentials Grant or Password Grant -
Finally give it a final touch by increasing the Refresh Token Lifespan value to
315,360,000(it should last for 10 years):
- Change Default Grant Type as per your need. NOTE: If you prefer to use Client Credentials grant (Service account style access without using real userid-password) then your admin must enable it. Client Credentials is only supported on instances where it is explicitly enabled by the ServiceNow administrator. Its not supported in Dev / Free instance.
-
Done! Now you can use Client ID and Client Secret when configuring OAuth Authentication parameters.
Enable Client Credentials Grant Type
-
Enable the Client Credentials Grant Type:
Go to System Properties > All Properties, create a new property named
glide.oauth.inbound.client.credential.grant_type.enabled, and set it to true. - Configure the OAuth Application: Navigate to System OAuth > Application Registry, click New, and select Create an OAuth API endpoint for external clients. Set the name and save the record. In the Default Grant Type field, select Client Credentials and associate it with the integration user.
API Connection Manager configuration
Just perform these simple steps to finish authentication configuration:
-
Set Authentication Type to
OAuth Client Credentials Grant (Must be enabled by Admin) [OAuth] - Optional step. Modify API Base URL if needed (in most cases default will work).
- Fill in all the required parameters and set optional parameters if needed.
- Finally, hit OK button:
ServicenowDSNServiceNowOAuth Client Credentials Grant (Must be enabled by Admin) [OAuth]https://[$InstanceName$].service-now.com/api/nowThere are no parameters to configure.
ServiceNow authentication
Authenticate using OAuth Password Grant (ServiceNow instance username, password, OAuth Client ID, and Client Secret). [API reference]
Create OAuth application and use it for authentication:
- Login to your instance at https://your-instance-id.service-now.com.
-
Start by clicking on menu item All, then search for oauth, and click Application Registry option:
-
Then click button New:
-
Continue by clicking Create an OAuth API endpoint for external clients option:
-
Move on by naming your OAuth application and entering a Client Secret (or let it be generated automatically).
- Click on the lock icon next to the Redirect URL. Enter
https://zappysys.com/oauth. This is not needed if you use Client Credentials Grant or Password Grant -
Finally give it a final touch by increasing the Refresh Token Lifespan value to
315,360,000(it should last for 10 years):
- Change Default Grant Type as per your need. NOTE: If you prefer to use Client Credentials grant (Service account style access without using real userid-password) then your admin must enable it. Client Credentials is only supported on instances where it is explicitly enabled by the ServiceNow administrator. Its not supported in Dev / Free instance.
-
Done! Now you can use Client ID and Client Secret when configuring OAuth Authentication parameters.
Enable Client Credentials Grant Type
-
Enable the Client Credentials Grant Type:
Go to System Properties > All Properties, create a new property named
glide.oauth.inbound.client.credential.grant_type.enabled, and set it to true. - Configure the OAuth Application: Navigate to System OAuth > Application Registry, click New, and select Create an OAuth API endpoint for external clients. Set the name and save the record. In the Default Grant Type field, select Client Credentials and associate it with the integration user.
API Connection Manager configuration
Just perform these simple steps to finish authentication configuration:
-
Set Authentication Type to
OAuth Password Grant [OAuth] - Optional step. Modify API Base URL if needed (in most cases default will work).
- Fill in all the required parameters and set optional parameters if needed.
- Finally, hit OK button:
ServicenowDSNServiceNowOAuth Password Grant [OAuth]https://[$InstanceName$].service-now.com/api/nowRequired Parameters User name Fill-in the parameter... Password Fill-in the parameter...
-
Then go to Preview tab to start building a SQL query.
-
Once you do that, proceed by opening Query Builder:
ZappySys API Driver - ServiceNowRead and write ServiceNow data effortlessly. Integrate, manage, and automate incidents, tasks, attachments, and records — almost no coding required.ServicenowDSN
-
Then simply select the Get Attachments By Parent Row Search endpoint (action).
-
Continue by configuring the Required parameters. You can also set optional parameters too.
-
Move on by hitting Preview Data button to preview the results.
-
If you see the results you need, simply copy the generated query:
-
Click OK to use built SQL query and close the Query Builder.
-
Now hit Preview Data button to preview the data using the generated SQL query. If you are satisfied with the result, use this query in Alteryx:
ZappySys API Driver - ServiceNowRead and write ServiceNow data effortlessly. Integrate, manage, and automate incidents, tasks, attachments, and records — almost no coding required.ServicenowDSN-- 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' )
You can also access data quickly from the tables dropdown by selecting <Select table>.AWHEREclause,LIMITkeyword will be performed on the client side, meaning that thewhole result set will be retrieved from the ServiceNow API first, and only then the filtering will be applied to the data. If possible, it is recommended to use parameters in Query Builder to filter the data on the server side (in ServiceNow servers).
Let's not stop here and explore SQL query examples, including how to use them in Stored Procedures and Views (virtual tables) in the next steps.
ServiceNow SQL query examples
Use these SQL queries in your Alteryx data source:
Read attachments by parent record
This example set demonstrates how to use the get_attachments_by_parent_search endpoint.
This endpoint first finds parent rows (for example, records in the problem table) using a parent-level Query, then for each parent record fetches attachments using the AttachmentQuery filter. Because it performs a per-parent lookup it can be slower than direct attachment-table queries, but it is useful when you must filter by parent record attributes (for example, problems updated in the last 2 days).
Use the AttachmentQuery to apply server-side filters on the sys_attachment table (examples: file_nameENDSWITH.png, content_typeSTARTSWITHimage/, size_bytes>1048576, or date placeholders like <<today-2d,FUN_TO_DATETIME>>). Replace sample sys_id and table names with values from your instance.
-- 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'
)
Create SQL view in ODBC data source
ZappySys API Drivers support flexible Query language so you can override Default Properties you configured on Data Source such as URL, Body. This way you don't have to create multiple Data Sources if you like to read data from multiple EndPoints. However not every application support supplying custom SQL to driver so you can only select Table from list returned from driver.
If you're dealing with Microsoft Access and need to import data from an SQL query, it's important to note that Access doesn't allow direct import of SQL queries. Instead, you can create custom objects (Virtual Tables) to handle the import process.
Many applications like MS Access, Informatica Designer wont give you option to specify custom SQL when you import Objects. In such case Virtual Table is very useful. You can create many Virtual Tables on the same Data Source (e.g. If you have 50 URLs with slight variations you can create virtual tables with just URL as Parameter setting.
-
Go to Custom Objects Tab and Click on Add button and Select Add Table:
-
Enter the desired Table name and click on OK:
-
And it will open the New Query Window Click on Cancel to close that window and go to Custom Objects Tab.
-
Select the created table, Select Text Type AS SQL and write the your desired SQL Query and Save it and it will create the custom table in the ZappySys Driver:
Here is an example SQL query for ZappySys Driver. You can insert Placeholders also. Read more about placeholders here
SELECT "ShipCountry", "OrderID", "CustomerID", "EmployeeID", "OrderDate", "RequiredDate", "ShippedDate", "ShipVia", "Freight", "ShipName", "ShipAddress", "ShipCity", "ShipRegion", "ShipPostalCode" FROM "Orders" Where "ShipCountry"='USA'
-
That's it now go to Preview Tab and Execute your custom virtual table query. In this example it will extract the orders for the USA Shipping Country only:
SELECT * FROM "vt__usa_orders_only"
Get attachments by parent row search in Alteryx via SQL view
-
Open Alteryx Designer.
-
First, verify your DCM Settings to ensure you can access ODBC drivers. Go to Options > User Settings > Edit User Settings.
If DCM Mode is set to DCM Only, change it to DCM Optional if you would like to access the legacy Generic ODBC Connection.
After changing this setting, you may need to click Save and restart the connection window for the "Generic ODBC" icon to appear. -
Drag an Input Data tool onto your Alteryx canvas.
-
In the Configuration pane, click Set Up a Connection.
-
Note for DCM Users: If your environment has DCM (Data Connection Manager) enabled, the classic "Generic ODBC" icon may be hidden. To find it, select Data sources on the left and type "ODBC" in the search bar.
-
Once the ODBC window opens, click Connect Asset and select your ServicenowDSN DSN from the list.
Ensure you have configured a 64-bit System DSN in the Windows ODBC Data Source Administrator before this step. -
After selecting your DSN, configure your SQL Query in the Input Data tool configuration:
-
To save your data, drag an Output Data tool and connect it to the Input Data tool.
-
Configure the Output Data tool to write to a CSV file:
-
Press Run (Ctrl+R) to execute the workflow. Verify the results in the Results Window at the bottom.
Advanced topics
Creating SQL stored procedures
You can create procedures to encapsulate custom logic and then only pass handful parameters rather than long SQL to execute your API call.
Steps to create Custom Stored Procedure in ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here
-
Go to Custom Objects Tab and Click on Add button and Select Add Procedure:
-
Enter the desired Procedure name and click on OK:
-
Select the created Stored Procedure and write the your desired stored procedure and Save it and it will create the custom stored procedure in the ZappySys Driver. Here is an example stored procedure for ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here
CREATE PROCEDURE [usp_get_orders] @fromdate = '<<yyyy-MM-dd,FUN_TODAY>>' AS SELECT * FROM Orders where OrderDate >= '<@fromdate>';
-
That's it now go to Preview Tab and Execute your Stored Procedure using Exec Command. In this example it will extract the orders from the date 1996-01-01:
Exec usp_get_orders '1996-01-01';
Conclusion
And there you have it — a complete guide on how to get attachments by parent row search in Alteryx without writing complex code. All of this was powered by ServiceNow ODBC Driver, which handled the REST API pagination and authentication for us automatically.
Download the trial now or ping us via chat if you have any questions or are looking for a specific feature (you can also reach out to us by submitting a ticket):
More actions supported by ServiceNow Connector
Got another use case in mind? We've documented the exact setups for a variety of essential ServiceNow operations directly in Alteryx, so you can skip the trial and error. Find your next step-by-step guide below:
- Delete a Table Row
- Delete Attachment
- Delete table row
- Download Table Attachment (Single - Using Id)
- Download Table Attachments (Multiple - Using Query)
- Download Table Attachments By Parent Row Search
- Get Attachments
- Get List Of System Tables Admin Use Sys Db Object
- Get List of Tables
- Get List Of Tables Admin Use Sys Db Object
- Get List Of User Tables Admin Use Sys Db Object
- Get Record Labels (Tags)
- Get Table Columns
- Get Table Columns Admin Use Sys Dictionary
- Get Table Row Count
- Get Table Rows
- Test Connection
- Update a Table Row
- Upload Attachment
- Make Generic REST API Request
- Make Generic REST API Request (Bulk Write)