C3 AI Documentation Home

ServiceNow Connector

The C3 Agentic AI Platform has a built-in Java Database Connectivity (JDBC) connector for integrating with ServiceNow databases.

To connect to ServiceNow from your application:

  1. Add a SqlSourceSystem modeling the ServiceNow source system to your package.
  2. Configure the JdbcCredentials authorizing the connection to the external ServiceNow table.
  3. Add a SqlSourceCollection modeling the target ServiceNow table to your package.
  4. Create an External Type modeling the schema of the external ServiceNow table.
  5. Fetch data through the External Type to confirm that the connection works.

For more information, see the ServiceNow driver documentation.

Model the source system

Create a SqlSourceSystem and set the name field as the identifier for the external database system.

For example, add the following ServiceNowSourceSystem.json to the \metadata\SqlSourceSystem directory of your package:

JSON
{
    "name": "ServiceNowSourceSystem"
}

Configure the credential used to authorize the JDBC connection

In the C3 AI Console, create a JdbcCredentials Type instance to configure the connection to the external ServiceNow database.

JavaScript
var credsRaw = {
    "url": "jdbc:servicenow:URL=< SERVER_HOSTNAME >",
    "username": "< DB_USERNAME >",
    "password": "< DB_PASSWORD >",
    "datastore": DatastoreType.SERVICENOW
    }

creds = JdbcCredentials.make(credsRaw)

SqlSourceSystem.forName("ServiceNowSourceSystem").setCredentials(creds);

Model the table containing the data

To model the external ServiceNow table in your application, create a SqlSourceCollection and set the following fields:

  • name: Identifier for the ServiceNow table
  • source: Name of the External Type that models the schema of the external ServiceNow table
  • sourceSystem: Name of the ServiceNow SqlSourceSystem

For example, to model a table called TestDocumentApproval, add the following TestDocumentApproval.json to the \metadata\SqlSourceCollection directory of your package:

JSON
{
    "name": "TestDocumentApproval",
    "source": "TestDocumentApproval",
    "sourceSystem" : {
      "name" : "ServiceNowSourceSystem"
    }
}

Model the table schema

To model the schema of the ServiceNow table in your application, create an External entity Type. Give the entity Type a schema name that matches the internal name of the table in ServiceNow.

Start by adding the following TestDocumentApproval.c3typ file to the \src directory of your package:

Type
entity type TestDocumentApproval mixes External, NoSystemCols schema name 'x_1385199_c3_test_document_approval_category'

Use the inferSourceType() method to see the C3 AI data types that the platform infers from the source data types of the table:

JavaScript
var schema = SqlSourceCollection.forName("TestDocumentApproval").inferSourceType().declaredFieldTypes;

var myObject = {};
for (let i = 0; i < schema.length; i++) {
        schemaName = schema[i].schemaName;
        myObject[schemaName] = schema[i].valueType.name;
    }

Inferred C3 data types for each column of the ServiceNow table

To validate the type inference, view the source data types:

JavaScript
SqlSourceCollection.forName("TestDocumentApproval").connect().columns;

Source columns of the ServiceNow table with their data types

Complete the External entity Type definition:

Type
entity type TestDocumentApproval mixes External, NoSystemCols schema name 'x_1385199_c3_test_document_approval_category' {

  id:             string schema name 'sys_id'
  active:         boolean schema name 'active'
  description:    string schema name 'description'
  name_:          string schema name 'name'
  number:         string schema name 'number'
  sys_created_by: string schema name 'sys_created_by'
  sys_created_on: datetime no tz schema name 'sys_created_on'
  sys_mod_count:  int32 schema name 'sys_mod_count'
  sys_tags:       string schema name 'sys_tags'
  sys_updated_by: string schema name 'sys_updated_by'
  sys_updated_on: datetime no tz schema name 'sys_updated_on'
  use_flow:       string schema name 'use_flow'
  use_flow_link:  string schema name 'use_flow_link'
}
Type
@db(dataTypeOverride="ID_FIELD_DATA_TYPE")
id: ~ schema name "ID_FIELD"

Read data from the table

After you complete the External entity Type definition, validate the configuration. Fetch the External Type data from the ServiceNow table:

JavaScript
c3Grid(TestDocumentApproval.fetch());

TestDocumentApproval records fetched from ServiceNow

See also

Was this page helpful?