snow_record_find – Search for multiple records from ServiceNow — Ansible Documentation

- AnsibleFest
- Products
- Community
- Webinars & Training
- Blog

Documentation

# snow_record_find – Search for multiple records from ServiceNow

New in version 2.9.

- Synopsis
- Requirements
- Parameters
- Examples
- Return Values
- Status

## Synopsis

- Gets multiple records from a specified table from ServiceNow based on a query dictionary.

## Requirements

The below requirements are needed on the host that executes this module.

- python pysnow (pysnow)

## Parameters

Parameter | Choices/Defaults | Comments
--- | --- | ---
client_id string added in 2.9 |  | Client ID generated by ServiceNow.
client_secret string added in 2.9 |  | Client Secret associated with client id.
instance string |  | The ServiceNow instance name, without the domain, service-now.com. If the value is not specified in the task, the value of environment variable `SN_INSTANCE` will be used instead. Environment variable support added in Ansible 2.9.
max_records integer | Default: 20 | Maximum number of records to return.
order_by string | Default: "-created_on" | Field to sort the results on. Can prefix with "-" or "+" to change descending or ascending sort order.
password string |  | Password for username. Required whether using Basic or OAuth authentication. If the value is not specified in the task, the value of environment variable `SN_PASSWORD` will be used instead. Environment variable support added in Ansible 2.9.
query dictionary / required |  | Dict to query for records.
return_fields list |  | Fields of the record to return in the json. By default, all fields will be returned.
table string | Default: "incident" | Table to query for records.
username string |  | Name of user for connection to ServiceNow. Required whether using Basic or OAuth authentication. If the value is not specified in the task, the value of environment variable `SN_USERNAME` will be used instead. Environment variable support added in Ansible 2.9.

## Examples

    - name: Search for incident assigned to group, return specific fields
      snow_record_find:
        username: ansible_test
        password: my_password
        instance: dev99999
        table: incident
        query:
          assignment_group: d625dccec0a8016700a222a0f7900d06
        return_fields:
          - number
          - opened_at

    - name: Using OAuth, search for incident assigned to group, return specific fields
      snow_record_find:
        username: ansible_test
        password: my_password
        client_id: "1234567890abcdef1234567890abcdef"
        client_secret: "Password1!"
        instance: dev99999
        table: incident
        query:
          assignment_group: d625dccec0a8016700a222a0f7900d06
        return_fields:
          - number
          - opened_at

    - name: Find open standard changes with my template
      snow_record_find:
        username: ansible_test
        password: my_password
        instance: dev99999
        table: change_request
        query:
          AND:
            equals:
              active: "True"
              type: "standard"
              u_change_stage: "80"
            contains:
              u_template: "MY-Template"
        return_fields:
          - sys_id
          - number
          - sys_created_on
          - sys_updated_on
          - u_template
          - active
          - type
          - u_change_stage
          - sys_created_by
          - description
          - short_description

## Return Values

Common return values are documented here, the following are the fields unique to this module:

Key | Returned | Description
--- | --- | ---
record dictionary | always | The full contents of the matching ServiceNow records as a list of records.

## Status

- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]

### Authors

- Tim Rightnour (@garbled1)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.