Skip to content

Latest commit

 

History

History
120 lines (81 loc) · 4.14 KB

README.org

File metadata and controls

120 lines (81 loc) · 4.14 KB

snRDG

Generate Row Data Gateways[1] for ServiceNow Tables.

Prerequisites

  • Node.js (>= 12.x.x)
  • npm (>= 6.x.x)
  • A ServiceNow instance
  • API key for the ServiceNow instance

Installation

  1. Clone the repository:
    git clone https://github.com/julian-hoch/snRDG.git
        
  2. Install the dependencies:
    npm install -g
        
  3. Configure environment variables:

    Create a `.env` file in the root of your project and add the following variables:

    SNRDG_INSTANCE=<your_instance_name>
    SNRDG_API_KEY=<your_api_key>
        

    Replace `<your_instance_name>` with the name of your ServiceNow instance and `<your_api_key>` with your API key.

  4. Install the ServiceNow application:

    Import the provided update set XML into your ServiceNow instance.

  5. Configure API Key

    Create an API key in your ServiceNow instance and assign it to the REST API[2].

Usage

The following commands are available to interact with the ServiceNow instance:

Test Access

Ensure your environment is set up correctly, and you can access your ServiceNow instance.

snrdg test

This will test the connection and confirm the setup.

Get Schema

Retrieve the schema of a specific table in JSON format.

snrdg schema <table_name>

Replace `<table_name>` with the name of your ServiceNow table.

Generate Row Data Gateway Class

Generate a Row Data Gateway class for a given ServiceNow table.

snrdg generate <table_name> <class_name> [template]

Replace `<table_name>` with the name of your ServiceNow table and `<class_name>` with the desired name for the generated class.

The “template” parameter is optional. By default, a ES5 JavaScript class will be generated. There is also a template for an ES6 class available. You can use that with the template “class_es6”.

Example

Here’s an example of how to use the commands:

snrdg test
snrdg schema incident
snrdg generate incident IncidentRDG

Or, to get an ES6 class, and to directly store it in a file (adjust the path to your needs):

snrdg generate incident IncidentRDG ./templates/class_es6 > ./IncidentRDG.js

You can then upload the generated class to your ServiceNow instance and save it as a Script Include to use it in your scripts.

Architecture

The project consists of three main parts:

ServiceNow Application

The ServiceNow application is responsible for compiling the metadata of the table and provides a REST API to access the schema information. It is secured via an API key[3].

The installation can be installed using the provided update set XML (directory “app”). The source is also included in this GIT repository for convenience.

See directory sys_script_include.

Client

The client provides a simple CLI to query the instance and generate classes based on the table schema. The client is written in TypeScript and uses the Axios library for HTTP requests. To generate the class, the client uses the Eta template engine.

Templates

The templates for generating the classes are located in the /templates directory. The Eta template engine uses these templates to generate the JavaScript class code based on the table schema. Feel free to adjust the templates to your own needs, or to add new templates.

Contributing

Feel free to submit issues or pull requests. Any help is greatly appreciated!

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Authors

Developed by Julian Hoch.

Footnotes