Skip to content

Commit 5014a5f

Browse files
authored
UX Data Broker Transform Starter Template (#1573)
* Create template.js Added a starter template for a transform data resource. This template contains: - JSDoc type annotations - Destructured inputs - Try/catch - Error logging then throw (Enables error logging but still allows the data resource to fail) - An example of what the properties object should look like * Create readme.md * Update readme.md Fixed incorrect JSDoc optional syntax * Update template.js Fixed incorrect JSDoc optional syntax
1 parent 4a04f68 commit 5014a5f

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Transform Data Broker Template
2+
3+
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.
4+
5+
## Features
6+
7+
- **JSDoc Type Annotations** for clarity and type-checking.
8+
- **Destructured Inputs** for simplified parameter handling.
9+
- **Error Logging & Propagation**: Logs errors while allowing the data resource to fail if needed.
10+
- **Properties Example**: Provides an example of what the properties should look like
11+
12+
## Template Overview
13+
14+
```javascript
15+
/**
16+
* @param {{param1: string, param2: number, param3?: boolean}} inputs
17+
* Inputs from the properties field above; param1 and param2 are mandatory.
18+
* @returns {string} The value returned after transformation.
19+
*/
20+
function transform({ param1, param2, param3 }) {
21+
const lib = "Data Broker";
22+
const func = "<insert data broker name here>";
23+
let res;
24+
25+
try {
26+
if (!param1) throw new Error("Missing required param 'param1'");
27+
if (!param2) throw new Error("Missing required param 'param2'");
28+
29+
// Add transformation logic here
30+
31+
return res;
32+
} catch (e) {
33+
gs.error(`${lib} ${func} - ${e}`);
34+
throw new Error(e);
35+
}
36+
}
37+
38+
/**
39+
* TIPS
40+
* Make sure to flag mutates data if your data resource changes any data
41+
* Properties structure (these are the inputs for your data resource):
42+
[
43+
{
44+
"name": "param1",
45+
"label": "Param 1",
46+
"description": "An example of the first param as a string, mandatory",
47+
"readOnly": false,
48+
"fieldType": "string",
49+
"mandatory": true,
50+
"defaultValue": ""
51+
},
52+
{
53+
"name": "param2",
54+
"label": "Param 2",
55+
"description": "An example of the second param as a number, mandatory",
56+
"readOnly": false,
57+
"fieldType": "number",
58+
"mandatory": true,
59+
"defaultValue": ""
60+
},
61+
{
62+
"name": "param3",
63+
"label": "Param 3",
64+
"description": "An example of the third param as a boolean, optional",
65+
"readOnly": false,
66+
"fieldType": "boolean",
67+
"mandatory": false,
68+
"defaultValue": ""
69+
}
70+
]
71+
*/
72+
```
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* This is a starter template for a transform data broker with:
3+
* - JSDoc type annotations
4+
* - Destructured inputs
5+
* - Try/catch
6+
* - Error logging then throw (Enables error logging but still allows the data resource to fail)
7+
* @param {{param1: string, param2: number, param3?: boolean}} inputs inputs from the properties field above, param1 and param2 are mandatory
8+
* @returns {string} the value returned
9+
*/
10+
function transform({ param1, param2, param3 }) {
11+
const lib = "Data Broker";
12+
const func = "<insert data broker name here>";
13+
14+
/** @type {string} */
15+
let res;
16+
17+
try {
18+
// Handle required param checks
19+
if (!param1) throw new Error("Missing required param 'param1'");
20+
if (!param2) throw new Error("Missing required param 'param2'");
21+
22+
// Add logic here
23+
24+
return res;
25+
} catch (e) {
26+
gs.error(`${lib} ${func} - ${e}`);
27+
throw new Error(e);
28+
}
29+
}
30+
31+
/**
32+
* TIPS
33+
* Make sure to flag mutates data if your data resource changes any data
34+
* Properties structure (these are the inputs for your data resource):
35+
[
36+
{
37+
"name": "param1",
38+
"label": "Param 1",
39+
"description": "An example of the first param as a string, mandatory",
40+
"readOnly": false,
41+
"fieldType": "string",
42+
"mandatory": true,
43+
"defaultValue": ""
44+
},
45+
{
46+
"name": "param2",
47+
"label": "Param 2",
48+
"description": "An example of the second param as a number, mandatory",
49+
"readOnly": false,
50+
"fieldType": "number",
51+
"mandatory": true,
52+
"defaultValue": ""
53+
},
54+
{
55+
"name": "param3",
56+
"label": "Param 3",
57+
"description": "An example of the third param as a boolean, optional",
58+
"readOnly": false,
59+
"fieldType": "boolean",
60+
"mandatory": false,
61+
"defaultValue": ""
62+
}
63+
]
64+
*/

0 commit comments

Comments
 (0)