UNPKG

4.87 kBMarkdownView Raw
1# servicenow-skeleton-typescript
2
3## Initial Project Setup
4### Node Project Setup
5```bash
6npm i servicenow-dev-skeleton require-dir --save-dev
7node_modules\.bin\skeleton init
8typings install
9```
10
11### Configure servicenowconfig.js for your application
12- uri = path to your servicenow instance
13- application = sys_id of the ServiceNow scoped application your are developing
14
15### Set your personal username and password for ServiceNow authentication
16Attempt to run "gulp dts" task, if your .env file is not set up correctly this task will warn you can create the file.
17In the .env file, set your ServiceNow credentials.
18
19## How to use this skeleton for your SN App
20
21### Configuring your ServiceNow dev instance to work with this skeleton project
22There are two update sets that are needed for this project to work with your dev instances. It relies on a u_typescript field added to all tables that you will be writing typescript for (business rules, script includes, etc),
23as well as a scripted rest API for the automatic DTS generator to query schema for any tables it finds in your source files. Neither of these update sets (or any other u_typescript fields) should move beyond your dev instances!
24
25- Import the update set in integration\typescript_integration_udpate_set.xml This adds a u_typescript field to the sys_script and sys_script_include tables for storing the typescript.
26- The automatic dts generation requires a SN rest endpoint to query for the table schemas it finds in your ts files. import the update set xml integration\restschema_update_set.xml (only works in Geneva or later).
27
28### Source Control
29Since SN natively integrates with GIT starting in Helsinki, you can extend any tables you are developing with a u_typescript field to store your typescript source so that it gets commited to your repo via SN, and you can track changes to those scripts.
30
31### Adding a new script include, business rule, or other script file for development
32When working on a new business rule or script include, first add it in the servicenow studio editor. After you save the new item, come back to this project and run "gulp pull", this will scan the ServiceNow Application for any script files and create them in your development environment under src\[tablename] folder.
33
34Once the item is listed (example: "src\sys_script\foo.js"), change the extension to .ts and convert it to typescript. When you are ready to upload the changes, run "gulp push" task to upload both the transpiled javascript as well as your typescript source back into SN.
35
36You should periodically sync or pull the application when working with other developers, to get the latest changes. WARNING: This will overwrite any file you have in src\ folder with the version found in the ServiceNow application. Be sure to upload any changes you have first, or save them off separately to re-apply if needed.
37
38You can now commit this change inside SN as you normally would in your development process to save both the typescript and js. At any time you can delete the src\ folder and run gulp task "sync" to re-sync with whats in servicenow! If you do not wish to use typescript, leave the file as a .js extension and develop as your normally would.
39
40### DTS Generation
41As you write your code, any GlideRecord('[table_name]') source you create can be automatically scanned for typings generation by running the "gulp dts" task (automatically run by the "sync" task also). This task will scan all .ts files in the src\ folder and detect any GlideRecord references and download d.ts schema for them.
42
43If you need to manually add a reference to a table that may not be used via GlideRecord call such as dot walking, then a JSDoc comment anywhere in the ts file, and use add dts: followed by a comma delimited string of the table names
44```javsacript
45/** dts: tablename1,tablename2 */
46```
47
48A ServiceNow DTS is maintained at https://github.com/bryceg/servicenow-dts
49
50## Adding new tables for development
51Configure servicenowconfig types variable with the new servicenow types:
52```javascript
53 types: {
54 my_new_type: {js: 'js_field_name', ts: 'typescript_field_name'}
55 }
56```
57
58## Gulp Tasks Usage
59
60### gulp dts
61Generates a servicenow.d.ts file from the servicenowconfig dts section. This will scan all .ts files and locate any type references for GlideRecords.
62
63### gulp pull
64Syncronizes your environment with the ServiceNow application specified in your config file. Similar to "git pull"
65
66*WARNING*: This will overwrite any src files your have not uploaded to SN yet, so be sure to run sn-pull first or prepare for any edited files to be overwritten!
67
68### gulp push
69Compliles any typescript to javascript and uploads the results to the application
70
71### gulp sync
72Runs the pull and dts tasks
73
74WARNING: See gulp pull task