Skip to content

UX Data Broker Transform Starter Template #1572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions UX Data Broker Transform/starter-template/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Transform Data Broker Template

This repository provides a starter template for creating Transform Data Brokers in ServiceNow’s UX framework. This template includes error handling, input validation, and JSDoc annotations for a streamlined setup.

## Features

- **JSDoc Type Annotations** for clarity and type-checking.
- **Destructured Inputs** for simplified parameter handling.
- **Error Logging & Propagation**: Logs errors while allowing the data resource to fail if needed.
- **Properties Example**: Provides an example of what the properties should look like

## Template Overview

```javascript
/**
* @param {{param1: string, param2: number, param3: [boolean]}} inputs
* Inputs from the properties field above; param1 and param2 are mandatory.
* @returns {string} The value returned after transformation.
*/
function transform({ param1, param2, param3 }) {
const lib = "Data Broker";
const func = "<insert data broker name here>";
let res;

try {
if (!param1) throw new Error("Missing required param 'param1'");
if (!param2) throw new Error("Missing required param 'param2'");

// Add transformation logic here

return res;
} catch (e) {
gs.error(`${lib} ${func} - ${e}`);
throw new Error(e);
}
}

/**
* TIPS
* Make sure to flag mutates data if your data resource changes any data
* Properties structure (these are the inputs for your data resource):
[
{
"name": "param1",
"label": "Param 1",
"description": "An example of the first param as a string, mandatory",
"readOnly": false,
"fieldType": "string",
"mandatory": true,
"defaultValue": ""
},
{
"name": "param2",
"label": "Param 2",
"description": "An example of the second param as a number, mandatory",
"readOnly": false,
"fieldType": "number",
"mandatory": true,
"defaultValue": ""
},
{
"name": "param3",
"label": "Param 3",
"description": "An example of the third param as a boolean, optional",
"readOnly": false,
"fieldType": "boolean",
"mandatory": false,
"defaultValue": ""
}
]
*/
```
64 changes: 64 additions & 0 deletions UX Data Broker Transform/starter-template/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* This is a starter template for a transform data broker with:
* - JSDoc type annotations
* - Destructured inputs
* - Try/catch
* - Error logging then throw (Enables error logging but still allows the data resource to fail)
* @param {{param1: string, param2: number, param3: [boolean]}} inputs inputs from the properties field above, param1 and param2 are mandatory
* @returns {string} the value returned
*/
function transform({ param1, param2, param3 }) {
const lib = "Data Broker";
const func = "<insert data broker name here>";

/** @type {string} */
let res;

try {
// Handle required param checks
if (!param1) throw new Error("Missing required param 'param1'");
if (!param2) throw new Error("Missing required param 'param2'");

// Add logic here

return res;
} catch (e) {
gs.error(`${lib} ${func} - ${e}`);
throw new Error(e);
}
}

/**
* TIPS
* Make sure to flag mutates data if your data resource changes any data
* Properties structure (these are the inputs for your data resource):
[
{
"name": "param1",
"label": "Param 1",
"description": "An example of the first param as a string, mandatory",
"readOnly": false,
"fieldType": "string",
"mandatory": true,
"defaultValue": ""
},
{
"name": "param2",
"label": "Param 2",
"description": "An example of the second param as a number, mandatory",
"readOnly": false,
"fieldType": "number",
"mandatory": true,
"defaultValue": ""
},
{
"name": "param3",
"label": "Param 3",
"description": "An example of the third param as a boolean, optional",
"readOnly": false,
"fieldType": "boolean",
"mandatory": false,
"defaultValue": ""
}
]
*/
Loading