---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# TransformerDefinition - Scoped, Global

# TransformerDefinition - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

The TransformerDefinition API provides methods to instantiate and
manage the TransformerDefinition object, which associates a transformation rules list and a
record path.

This API works along with the Transformer and TransformerRuleList APIs. Together, these APIs transform XML nodes or any entity in a structured JSON document into an output of name-value pairs. Supported JSON entities including objects and elements within an array, such as strings, numbers, and other arrays.  
* The
  TransformerRuleList API enables you to create transformation
  rule lists that define what data in the source document to include in the output and
  how to transform the source data.

* The
  TransformerDefinition API associates a transformation rule list
  with a JSON/XML record path to define reusable transform definition objects. You can
  use a transform definition object to transform one or more source documents.

{#TransformerDefinitionAPI__ul_otj_sgv_bkb}

In addition, this object provides methods that enable you to obtain the record path of the
TransformerDefinition object. It can also validate whether the definition has a valid
TransformerRuleList associated with it.

The Transformer API performs
the actual data transformation, one data entity at a time, using the specified
transformation rule list to create the desired output data.

You can use the TransformerDefinition class in both scoped and global
server scripts. When using this class, use the `sn_tfrm` namespace identifier.
Also, before this API is available in an instance, you must activate the Transformation
Service plugin (com.glide.transform).

## TransformerDefinition - TransformerDefinition(Object transformerRuleList, String
recordPath) {#ariaid-title2}

Instantiates a TransformerDefinition object.
{#TRD-transformerDefinition_O_S__table_sf4_rby_qhb__entry__3}

| Name | Type | Description |
|-|-|-|
| transformerRuleList | Object | TransformerRuleList to associate with this transformer definition. |
| recordPath | String | Optional. The path (JSONPath for JSON, XPath for XML) that identifies the container (parent) of nodes to parse as records in the source document. For JSON documents, these nodes can be any object, array, or JSON primitive (string, number, boolean). For XML documents, these nodes are the child elements of the container. If recordPath is unspecified, the entire document is inferred as a single record. For JSON documents, if the top node is an array and recordPath is unspecified, then the top array is the record's container, and each of its entries is a record. |
[Table 1. Parameters]

{#TRD-transformerDefinition_O_S__table_sf4_rby_qhb}  

    var stockAPI = new sn_ws.RESTMessageV2('Stock Details', 'Default GET'); 
    var response = stockAPI.execute(); 
    var responseBody = response.getBody(); 

    var transformerRuleList = new sn_tfrm.TransformerRuleList()
      .fromJSON()
      .addSymbol('ticker', 'quote.symbol') 
      .addSymbol('change_percentage', 'quote.change_change') 
      .thenMultiply('100') 
      .thenRoundDown('0') 
      .addSymbol('close_price', 'quote.close') 
      .thenAdaptCurrency('USD', false) 
      .addSymbol('summary') 
      .thenConcat('Shares of ') 
      .thenConcatSymbol('ticker') 
      .thenConcat(' closed at ') 
      .thenConcatSymbol('close'); 

     
    var path = '$.*'; // Transform all objects in the JSON document
    var transformerDefinition = new sn_tfrm.TransformerDefinition(transformerRuleList, recordPath); 
    var transformer = new sn_tfrm.Transformer(transformerDefinition, responseBody); 

    var results = []; 
    while (transformer.transform()) { 
      results.push(transformer.getRow());
    }

## TransformerDefinition - TransformerDefinition(String transformerDefinitionSysId) {#ariaid-title3}

Instantiates a TransformerDefinition object using an existing transformer definition.
{#TRD-TransformerDefinition_S__table_cfj_yr5_qxb__entry__3}

| Name | Type | Description |
|-|-|-|
| transformerDefinitionSysId | String | Sys_id of a transformer definition. Located in the Record Transformer \[sys_record_transformer\] table. |
[Table 2. Parameters]

{#TRD-TransformerDefinition_S__table_cfj_yr5_qxb}  
This example instantiates a TransformerDefinition object based on the provided sys_id.

    var transformerDefinition = new sn_tfrm.TransformerDefinition("7208b59743542110d4dc2c78c9b8f2e2");

## TransformerDefinition - recordPath() {#ariaid-title4}

If set when the TransformerDefinition object was instantiated, returns the record path
for the source data file associated with the TransformerDefinition object.
A record path (JSONPath for JSON, XPath for XML) identifies the container
(parent) of nodes to parse as records in the source document.

For JSON
documents, these nodes can be any object, array, or JSON primitive (string, number,
boolean). For XML documents, these nodes are the child elements of the
container.

If recordPath is unspecified, the entire
document is inferred as a single record. For JSON documents, if the top node is an
array and recordPath is unspecified, then the top array is the
record's container, and each of its entries is a record.
{#TRD-recordPath__table_nrv_kdy_qhb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#TRD-recordPath__table_nrv_kdy_qhb} {#TRD-recordPath__table_orv_kdy_qhb__entry__2}

| Type | Description |
|-|-|
| String | If set, the record path associated with the transformer definition. If not set, returns null. |
[Table 4. Returns]

{#TRD-recordPath__table_orv_kdy_qhb}  

    var path = '$.records'; 
    var transformerDefinition = new sn_tfrm.TransformerDefinition(transformerRuleList, recordPath); 
    var transformer = new sn_tfrm.Transformer(transformerDefinition, responseBody);  
    .
    .
    .

    var recordPath = transformerDefinition.recordfPath();

    var results = []; 
    while (transformer.transform()) { 
      results.push(transformer.getRow());
    }

## TransformerDefinition - validate() {#ariaid-title5}

Validates whether a valid TransformerRuleList is associated with the
TransformerDefintion object.
{#TRD-validate__table_jlv_hgy_qhb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 5. Parameters]

{#TRD-validate__table_jlv_hgy_qhb} {#TRD-validate__table_klv_hgy_qhb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether a valid TransformerRuleList is associated with the specified TransformerDefintion object. Valid values: * true: Valid TransformerRuleList associated * false: Invalid or no TransformerRulList associated {#TRD-validate__ul_d4k_wgy_qhb} |
[Table 6. Returns]

{#TRD-validate__table_klv_hgy_qhb}  

    var transformerDefinition = new sn_tfrm.TransformerDefinition(transformerRuleList, recordPath);
    var transformer = new sn_tfrm.Transformer(transformerDefinition, responseBody); 
    .
    .
    .

    if (transformerDefinition.validate()) {

      var results = []; 
      while (transformer.transform()) { 
        results.push(transformer.getRow());
      }
    }


