Skip to main content

snow-query-for-records

info

This promotion step is only available in Kargo on the Akuity Platform, versions v1.9.0 and above.

This page is for snow-query-for-records step. You can query for a ServiceNow record (returns the first matching record) using this step. Check below for other ServiceNow promotion steps.

ServiceNow integration for kargo is a group of promotion steps:

  1. snow-create
  2. snow-update
  3. snow-delete
  4. snow-query-for-records
  5. snow-wait-for-condition

These steps provide a comprehensive integration with ServiceNow, allowing you to create, update, delete, query for records, and track promotion workflows. This is particularly useful for maintaining traceability between your promotion processes and project management activities.

All the steps above support different record types in ServiceNow including managing Change Requests, Incidents, Problems etc.,. This integration also provides condition tracking through snow-wait-for-condition, making it a powerful tool for promotion workflows that require coordination with project management systems.

Using the API

Most of the time you cannot use the field labels you see in the ServiceNow UI as keys in the REST API. For example, if you want to set the value for the “Short description” field:

You can't use Short description in the REST API. You need to use short_description as the key and set the value via REST API parameters. To find the correct key for a field, right-click on the field and click Configure Dictionary:

column_name is the key:

To see choices available for a particular field e.g., State, right click on the field and click on Show Choice List to see the available choices for use in the steps:

For example New is -1 and Scheduled is -2

Configuration

Credentials

All ServiceNow operations require proper authentication credentials stored in a Kubernetes Secret.

NameTypeRequiredDescription
credentials.secretNamestringYName of the Secret containing the ServiceNow credentials in the project namespace.
credentials.typestringYType of ServiceNow credentials to use for authentication (either api-token or basic).

For credentials.type: api-token the referenced Secret should contain the following keys:

  • apiToken: ServiceNow API Token (see this blog post for how to create an API token in ServiceNow).
  • instanceURL: Your ServiceNow instance URL.

For credentials.type: basic the referenced Secret should contain the following keys:

  • username: Username of the ServiceNow user (you may want to create a user specifically for this integration).
  • password: Password of the ServiceNow user (for how to set the password for a user, see this).
  • instanceURL: Your ServiceNow instance URL.

Record

NameTypeRequiredDescription
tableNamestringYTable name of the record type you want to query (e.g., incident, problem, change_request).
queryobjectYSpecify your query parameters on which you want to filter the records. For supported parameters, please see the official documentation here.

Output

The output is a ServiceNow record. All fields are available for use in subsequent steps.

NameTypeDescription
recordobjectThe found ServiceNow record object containing all fields.

Example

This example searches for Change Requests with a specific record number:

steps:
- as: snowquery
config:
credentials:
namespace: kargo-demo
secretName: snow-creds
type: api-token
query:
number: CHG0000007
tableName: change_request
uses: snow-query-records
# Use the queried record in subsequent steps
- as: snowupdate
config:
credentials:
secretName: snow-creds
type: api-token
parameters:
short_description: Update incident for ${{ vars.imageRepo }}:${{
imageFrom(vars.imageRepo).Tag }} to resolved
tableName: change_request
template:
type: standard
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-update

Different E2E Workflows

These examples demonstrate the different steps supported for ServiceNow integration.

Change API Workflow

  - as: snowcreate
config:
credentials:
secretName: snow-creds
type: api-token
parameters:
impact: "3"
short_description: Deploy to ${{ ctx.stage }} complete for ${{ vars.imageRepo
}}:${{ imageFrom(vars.imageRepo).Tag }}
urgency: "3"
tableName: change_request
template:
templateId: ed89b72c83c172104517e470ceaad30a
type: standard
uses: snow-create
- as: snowquery
config:
credentials:
namespace: kargo-demo
secretName: snow-creds
type: api-token
query:
number: ${{ task.outputs.snowcreate.number }}
tableName: change_request
uses: snow-query-records
- as: snowupdate
config:
credentials:
secretName: snow-creds
type: api-token
parameters:
short_description: Update deployment for ${{ vars.imageRepo }}:${{
imageFrom(vars.imageRepo).Tag }} to resolved
tableName: change_request
template:
type: standard
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-update
- as: snow-wait-for-condition
config:
condition: state=-2
credentials:
namespace: kargo-demo
secretName: snow-creds
type: api-token
tableName: change_request
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-wait-for-condition
- as: snowdelete
config:
credentials:
secretName: snow-creds
type: api-token
tableName: change_request
template:
type: standard
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-delete

Table API Workflow

  - as: snowcreate
config:
credentials:
secretName: snow-creds
type: api-token
parameters:
impact: "3"
short_description: Deploy to ${{ ctx.stage }} complete for ${{ vars.imageRepo }}:${{ imageFrom(vars.imageRepo).Tag }}
urgency: "3"
tableName: incident
uses: snow-create
- as: snowquery
config:
credentials:
namespace: kargo-demo
secretName: snow-creds
type: api-token
query:
number: ${{ task.outputs.snowcreate.number }}
tableName: incident
uses: snow-query-records
- config:
ticketId: ${{ task.outputs.snowquery.sys_id }}
credentials:
secretName: snow-creds
type: api-token
parameters:
short_description: Update deployment for ${{ vars.imageRepo }}:${{ imageFrom(vars.imageRepo).Tag }} to resolved
tableName: incident
uses: snow-update
- as: snow-wait-for-condition
config:
condition: state=6
credentials:
namespace: kargo-demo
secretName: snow-creds
type: api-token
tableName: incident
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-wait-for-condition
- as: snowdelete
config:
credentials:
secretName: snow-creds
type: api-token
tableName: incident
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-delete

Here's a Table API workflow with Change Request:

  - as: snowcreate
config:
credentials:
secretName: snow-creds
type: api-token
parameters:
impact: "3"
short_description: Deploy to ${{ ctx.stage }} complete for ${{ vars.imageRepo
}}:${{ imageFrom(vars.imageRepo).Tag }}
urgency: "3"
tableName: change_request
uses: snow-create
- as: snowquery
config:
credentials:
namespace: kargo-demo
secretName: snow-creds
type: api-token
query:
number: ${{ task.outputs.snowcreate.number }}
tableName: change_request
uses: snow-query-records
- as: snowupdate
config:
credentials:
secretName: snow-creds
type: api-token
parameters:
short_description: Update deployment incident for ${{ vars.imageRepo }}:${{
imageFrom(vars.imageRepo).Tag }} to resolved
tableName: change_request
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-update
- as: snow-wait-for-condition
config:
condition: state=-2
credentials:
namespace: kargo-demo
secretName: snow-creds
type: api-token
tableName: change_request
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-wait-for-condition
- as: snowdelete
config:
credentials:
secretName: snow-creds
type: api-token
tableName: change_request
ticketId: ${{ task.outputs.snowquery.sys_id }}
uses: snow-delete