|
| 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 | +``` |
0 commit comments