Generate Row Data Gateways[1] for ServiceNow Tables.
- Node.js (>= 12.x.x)
- npm (>= 6.x.x)
- A ServiceNow instance
- API key for the ServiceNow instance
- Clone the repository:
git clone https://github.com/julian-hoch/snRDG.git
- Install the dependencies:
npm install -g
- 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.
- Install the ServiceNow application:
Import the provided update set XML into your ServiceNow instance.
- Configure API Key
Create an API key in your ServiceNow instance and assign it to the REST API[2].
The following commands are available to interact with the ServiceNow instance:
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.
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 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”.
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.
The project consists of three main parts:
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
.
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.
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.
Feel free to submit issues or pull requests. Any help is greatly appreciated!
This project is licensed under the GPL-3.0 License. See the LICENSE file for details.
Developed by Julian Hoch.
- [1]: See: P of EAA: Row Data Gateway
- [2]: The application includes a dummy API key you can adjust. See Inbound REST API Keys - ServiceNow Community for a detailed guide on how to use API keys in ServiceNow.
- [3]: See: Product Documentation | ServiceNow | API key credentials