Once you are familiar with the basics of ServiceNow table maps, including the difference between inbound and outbound table maps, how to create a table map, and how to add a table map to bulk shares, there are optional features you can configure based on your needs. 

What's on this page?




Customize your target database schema using table maps

By default, data replicated from existing tables will automatically create the same schema at the replicated database. The targeted database schema of replication needs to be flexible and customized in certain situations, such as: 

  • An existing schema that the replicated data need to fit in
  • A need to rename the field names or transform the field values using script at the source
  • The resulting field types need to be modified to a specific type or field length

Customizing your target database schema is done by using table maps in your share. 

Here's how:

Instructions:

  1. In your sharing ServiceNow instance, go to Perspectium > Control and Configuration Table Maps

  2. Select the table map you want to use (for the example, we'll use the table Incident to Common Incident), review the information in the fields, and check the Generate schema box. 

    (warning) WARNINGIf there are multiple table maps with the same Target table name, the DataSync Agent will retrieve the first record when querying against ServiceNow for the schema.

    NOTES:
    • Checking the Generate schema box is required in the initial sharing of your records
    • The value specified in the Target table name field will be used as the name of the table in the database. When the DataSync Agent queries the instance for the table's schema, if it cannot find a table map with a matching Target table name, it will then look for a table that matches the value in the Type field instead.

  3. To share the table map output, you need to crate a share and select the table map from step 1 in the Table map field. The generated payload can be subscribed by the DataSync Agent and the schema created dynamically.

    In this example, the common_incident table map will result in the following table schema, if consumed by the DataSync Agent for MySQL.

    mysql> describe common_incident;
    +---------------------+--------------+------+-----+---------+-------+
    | Field               | Type         | Null | Key | Default | Extra |
    +---------------------+--------------+------+-----+---------+-------+
    | state               | mediumtext   | YES  |     | NULL    |       |
    | short_description   | varchar(160) | YES  |     | NULL    |       |
    | description         | mediumtext   | YES  |     | NULL    |       |
    | priority            | mediumtext   | YES  |     | NULL    |       |
    | attachments         | mediumtext   | YES  |     | NULL    |       |
    | category            | mediumtext   | YES  |     | NULL    |       |
    | correlation_id      | varchar(100) | YES  |     | NULL    |       |
    | number              | varchar(40)  | YES  |     | NULL    |       |
    | correlation_display | varchar(100) | YES  |     | NULL    |       |
    | caller_id           | mediumtext   | YES  |     | NULL    |       |
    | caller_email        | varchar(100) | YES  |     | NULL    |       |
    | caller_full_name    | mediumtext   | YES  |     | NULL    |       |
    | comments            | mediumtext   | YES  |     | NULL    |       |
    | sys_id              | varchar(224) | NO   | PRI |         |       |
    | work_notes          | mediumtext   | YES  |     | NULL    |       |
    +---------------------+--------------+------+-----+---------+-------+
    15 rows in set (0.00 sec)

The sys_id field is created as GUID (PRI key) and contains number values to be used for lookup during updates/deletes. This is consistent with replicating database views.

↑ Go to top of page




Use scripts to serialize records

Table maps can be configured to use scripts to serialize the record yourself. Within the script, you can set the variable answer to be the value you want the record to be serialized and returned as. 

This is an advance configuration. Contact Perspectium Support for more information. 

The following variables are available to use:

VariableDescription
currentThis represents the record that is being shared
gr_tablemapThis represents the outbound table map itself. For example if you want to access the table map's name, you can use gr_tablemap.u_name

Instructions: 

  1. In your ServiceNow instance, go to Perspectium > Control and Configuration > Table Maps.

  2. Select the table map that you want to add a script to or create a new table map.

  3. Under the Mapping Script section, check the Use Script box.

  4. Fill the Script field with the appropriate script. See below for an example script.

  5. Click Update.

Example of a table map script

Click to reveal
/*
 * Custom Table Map
 */
 
answer = "<common_incident><description>" 
        + current.active + " with value " 
        + gr_tablemap.name + "</description></common_incident>";   

↑ Go to top of page




Field mappings in table maps

This feature allows you to map fields in the outbound record based on values from the ServiceNow record to be shared.

Prerequisites:

Instructions:

  1. In your ServiceNow instance, go to Perspectium > Control and Configuration > Table Maps.

  2. In the PSP Table Field Maps section, click New.

    Alternatively, you can click Add all source table fields. This allows you to quickly add all fields of the specified source table as field maps. This can be useful for cases where you want all fields to be in the outbound table map and only want to modify a few fields to have different values. 

  3. Set the following required fields:

    • Set the Source Field with the name of the field in the source table
    • Set the Target Field with the name of the field in the target table

  4. Optionally, you can set the Field Type and Field Length fields if using the Generate Schema option mentioned above, the Use Script option to do scripting for this field map (see below) or select the Add CDATA Tags if the content of this field map should be wrapped for content that needs to be escaped for sharing out in XML i.e. <short_description><![CDATA[field value characters with markup]]></short_description>.

  5. Click Submit.


↑ Go to top of page




Use script in field mappings

Using scripts, you an enhance or create new columns of data in your table map's field mapping. Here's how:

Prerequisites:

Instructions:

  1. In your ServiceNow instance, go to Perspectium > Control and Configuration > Table Maps.

  2. Find and click into the desired table map.

  3. In the PSP Table Field Maps section, click the desired field map.

  4. Check the Use Script box, which will reveal a Source Script field.

  5. Enter your script into the Source Script field

  6. Click Update.

Example of using scripting in field mappings

There are various ways you can use scripting in your field mappings. Here is an example:

Set mapping field value

To set an overall value for your field mapping, use the following: 

answer = "Priority ticket"; 

↑ Go to top of page




For other ways to utilize scripting in your field mappings, contact Perspectium Support.

  • No labels