Skip to content

Commit 3fe4b58

Browse files
committed
Massive README updates
Add pull and push command line option support to allow integration with third party build tools (see README for more details) Allow subDirPattern to use display values instead of sys_ids Add search support to download the whole record (for reference only) and optionally ignore individual field files
1 parent 45e975b commit 3fe4b58

File tree

7 files changed

+354
-63
lines changed

7 files changed

+354
-63
lines changed

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# FileSync Changes
22

3+
* 2016-07-17 (**Version 4.2.0**)
4+
* Massive README updates
5+
* Add pull and push command line option support to allow integration with third party build tools (see README for more details)
6+
* Eg. `node bin/app.js --config config.json --pull "ui_pages/attachment.xhtml"`
7+
* Eg. `node bin/app.js --config config.json --push "ui_pages/attachment.xhtml"`
8+
* Allow subDirPattern to use display values instead of sys_ids
9+
* Add search support to download the whole record (for reference only) and optionally ignore individual field files
10+
* Eg. `node bin/app.js --config config.json --search stories --record_only`
11+
* Eg. `node bin/app.js --config config.json --search team --full_record`
12+
313
* 2016-07-16 (**Version 4.1.3**)
414
* Fix issue where multiple suffixes might get confused depending on order in folder config (fixes #30)
515

README.md

Lines changed: 107 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sn-filesync -- ServiceNow FileSync (v4.1.3)
1+
sn-filesync -- ServiceNow FileSync (v4.2.0)
22
=================
33

44
[![NPM](https://nodei.co/npm/sn-filesync.png)](https://nodei.co/npm/sn-filesync/)
@@ -25,6 +25,7 @@ sn-filesync -- ServiceNow FileSync (v4.1.3)
2525
* [Search Usage](#search-usage)
2626
* [Search Command Line Usage](#search-command-line-usage)
2727
* [Tips for Searching](#tips-for-searching)
28+
* [Pull and Push Commands] (#pull-and-push-commands)
2829
* [Road Map](#road-map)
2930
* [Contribution workflow](#contribution-workflow)
3031
* [Changes](#changes)
@@ -84,45 +85,54 @@ FileSync is primarily driven via the command line. Windows users can of course c
8485

8586
The following demos assume a config file in `~/project/test/config.json` and records in `~/project/test/records/`
8687

87-
**Start**
88+
* Start
8889

89-
`node bin/apps.js --config ~/project/test/config.json`
90+
`node bin/apps.js --config ~/project/test/config.json`
9091

91-
**Download the script field from a script include**
92+
* Download the script field from a script include
9293

93-
`touch ~/project/test/records/script_includes/JSUtil.js`
94+
`touch ~/project/test/records/script_includes/JSUtil.js`
9495

95-
**Get help on options**
96+
* Get help on options
9697

97-
`node bin/app.js --help`
98+
`node bin/app.js --help`
9899

99-
**Use search to find records to sync**
100+
* Use search to **find** records to sync
100101

101-
`node bin/apps.js --config ~/project/test/config.json --search mine`
102+
`node bin/apps.js --config ~/project/test/config.json --search mine`
102103

103-
**Use search to download found records**
104+
* Use search to **download** found records
104105

105-
`node bin/apps.js --config ~/project/test/config.json --search mine --download`
106+
`node bin/apps.js --config ~/project/test/config.json --search mine --download`
107+
108+
* Use search to download records including the complete record as JSON (useful to reference)
109+
110+
`node bin/app.js --config ~/project/test/config.json --search mine --download --full_record`
111+
112+
* Update all local files with the latest version from the instance
113+
114+
`node bin/app.js --config ~/project/test/config.json --resync`
106115

107116
See also [Search Command Line Usage](#search-command-line-usage) for more details.
108117

109118

110119

111-
As you make changes to mapped files, you'll see messages logged showing the sync processing.
120+
As you make changes to mapped files, you'll see messages and notifications on the sync status.
112121

113122
If you are using the default config then you will already have all the appropriate folders created for you and some test script include files that will have been downloaded from the instance. See "preLoad" and "createAllFolders" options below.
114123

115-
Additionally, you can sync more files by adding an empty file corresponding to an instance record. You can do this from your editor
124+
#### How to get fields to files and then update the instance record
125+
126+
You can sync more files by adding an empty file corresponding to an instance record. You can do this from your editor
116127
or IDE, or via the command line.
117128

118-
Adding the empty JSUtil.js file will cause FileSync to sync the (OOB) JSUtil script include to the file. Any changes to
119-
this local file will now be synced to the mapped instance.
129+
Adding an empty JSUtil.js file in the script_includes folder will cause FileSync to sync the (OOB) JSUtil script include to the file. Any changes to this local file will now be synced to the mapped instance.
120130

121-
The basic workflow is to initially create a script on ServiceNow (script include, business rule, ui script, etc.), then
122-
add an empty file of the same name (and mapped extension) to a mapped local folder.
131+
The basic workflow is to initially create a record/script on ServiceNow (script include, business rule, ui script, etc.), then
132+
add an empty file of the same name (and mapped extension) to a mapped local folder (defined in config and displayed at startup).
123133

124134
FileSync can not support creating new records in ServiceNow by simply adding local files since there are
125-
additional fields and rules that can not be evaluated locally. Always start by creating a new
135+
additional fields and rules that cannot be evaluated locally. Always start by creating a new
126136
record on the instance, then add the empty local file and start editing your script.
127137

128138
### app.config.json settings
@@ -259,6 +269,7 @@ NOT supported:
259269
Property | Values | Default | Purpose
260270
------------ | -------------------- | ------------- | -------------
261271
debug | Bool: true / false | false | Enable more verbose debugging. Useful to troubleshoot connection issues.
272+
search | Object | empty | Define search criteria for searching. See [Search Command Line Usage](#search-command-line-usage) for more details.
262273
ignoreDefaultFolders | Bool: true / false | false | If false then utilise record to folder mapping defined in **lib/records.config.json**.<br />If true then the **"folders"** property must be set as described below.
263274
folders | Object listing folders | not set (inherited) | See **lib/records.config.json** as an example for format and usage. If this property is defined then it will override that defined in **lib/records.config.json** on a per folder level. This is an easy way to specify more mappings without modifying core files. If "ignoreDefaultFolders " is set to true then **lib/records.config.json** is completely ignored and all mappings must be defined in the "folders" property.
264275
createAllFolders | Bool: true / false | false | Creates all folders specified by folders (if set) or the default **lib/records.config.json** file.
@@ -286,12 +297,12 @@ This is also useful if you want to create a backup of your current setup.
286297
Command Line Usage:
287298

288299
````
289-
./node-darwin src/app --config <config to use> --export <new config file>
300+
node bin/app.js --config <config to use> --export <new config file>
290301
````
291302

292303
Eg.
293304
````
294-
./node-darwin src/app --config ~/.filesync/app.config-acme.json --export ~/Desktop/acme.config.json
305+
node bin/app.js --config ~/.filesync/app.config-acme.json --export ~/Desktop/acme.config.json
295306
````
296307

297308
The resulting json file will **not** include your authentication information. It will include the folder setup you used and a preLoadList listing all the records you have previously downloaded. This is very handy for getting new team members setup and providing them an easy reference to important files. Eg, for CMS development this could mean theme CSS/SASS, UI Macros, UI Pages and various script includes.
@@ -374,7 +385,17 @@ The search component enforces using the config file instead of the command line
374385
"query": "sys_created_on>javascript:gs.dateGenerate('2015-03-25','23:59:59')",
375386
"records_per_search": "1",
376387
"download": true // download all founds results
377-
}
388+
},
389+
"stories": {
390+
"table": "rm_story",
391+
"query": "active=true",
392+
"full_record": true // also include a JSON file representing the full record
393+
},
394+
"stories": {
395+
"table": "rm_story",
396+
"query": "active=true",
397+
"record_only": true // only the JSON file, no fields synced
398+
},
378399
},
379400

380401
```
@@ -383,16 +404,24 @@ The search component enforces using the config file instead of the command line
383404

384405
* Test the search system in demo mode:
385406
```
386-
./node-darwin src/app --config ~/my-conf.json --search
407+
node bin/app.js --config ~/my-conf.json --search
387408
```
388409
* Search based on a pre-defined search config (defined in *my-conf.json*):
389410
```
390-
./node-darwin src/app --config ~/my-conf.json --search mine
411+
node bin/app.js --config ~/my-conf.json --search mine
391412
```
392413
* Download records found via search (overwrites existing local files if they exist):
393-
```
394-
./node-darwin src/app --config ~/my-conf.json --search mine --download
395-
```
414+
```
415+
node bin/app.js --config ~/my-conf.json --search mine --download
416+
```
417+
* Additionally download the full record as JSON:
418+
```
419+
node bin/app.js --config ~/my-conf.json --search mine --download --full_record
420+
```
421+
* Download only the full record as JSON:
422+
```
423+
node bin/app.js --config ~/my-conf.json --search mine --download --full_record --record_only
424+
```
396425

397426
Note that the defaults are to search in demo mode without downloading any records.
398427

@@ -408,16 +437,66 @@ Search unlocks a great deal of potential. Here are some ideas showing how you ca
408437
* Export all description content or story content or ANY attribute from any table in bulk. Could identify documentation issues.
409438
* Export entire records but only the fields of interest. Eg, description field, script field, last modification date etc.
410439

440+
## Pull and Push Commands
441+
442+
The command line options `--pull` and `--push` allow integration with third party tools and scripts. Pull will retrieve a record given a **sys_id**, **search query** or **file path** which includes the table name and the file to save to. Depending on the input, either all defined fields in the config file will be output to files or just the field specified based on the file name suffix. Push will update the instance record field if the items are in sync.
443+
444+
Note that the default functionality for a pull is to download the file unlike when using `--search` which requires the `--download` option. Existing files will be overwritten.
445+
446+
### Pull Examples:
447+
448+
* Pull record via sys_id:
449+
```
450+
node bin/app.js --config ~/my-conf.json --pull "b1b390890a0a0b1e00f6ae8a31ee2697" --table sys_ui_page
451+
```
452+
* Pull record via sys_id (slightly slower search via all tables):
453+
```
454+
node bin/app.js --config ~/my-conf.json --pull "b1b390890a0a0b1e00f6ae8a31ee2697"
455+
```
456+
* Pull all defined fields for a record from a file path:
457+
```
458+
node bin/app.js --config ~/my-conf.json --pull "ui_pages/attachment"
459+
```
460+
* Pull a specific field for a record from a file path:
461+
```
462+
node bin/app.js --config ~/my-conf.json --pull "ui_pages/attachment.xhtml"
463+
```
464+
465+
* Pull record via search query:
466+
```
467+
node bin/app.js --config ~/my-conf.json --pull --search_query "name=attachment" --table sys_ui_page
468+
```
469+
470+
* Pull record via search query and save full record as JSON:
471+
```
472+
node bin/app.js --config ~/my-conf.json --pull --search_query "name=attachment" --table sys_ui_page --full_record
473+
```
474+
475+
476+
### Push Examples:
477+
478+
Push always ensures that records are in sync to avoid conflicts.
479+
480+
* Push a field value to the instance
481+
```
482+
node bin/app.js --config ~/my-conf.json --push "ui_pages/attachment.xhtml"
483+
```
484+
485+
* Push a field value to the instance (nested paths are supported!)
486+
```
487+
node bin/app.js --config ~/my-conf.json --push "business_rules/incident/before/insert_incident.js"
488+
```
411489

412490
## Road Map
413491

414492
Considering ServiceNow does not handle merge conflicts at all, this is a major goal of this tool! Contributions to help achieve this road map or improve the tool in general are **greatly** appreciated.
415493

416494
- [ ] instance comparison (eg. compare specific tables based on custom records)]
417-
- [ ] extend API to allow push and pull options that could be called from an external tool
495+
- [x] extend API to allow push and pull options that could be called from an external tool
496+
- [ ] Allow FileSync to be used in task build processes (extend API and 'pluggable' functionality)
418497
- [ ] allow configuring pre and post hooks (similar to a Grunt/Gulp/Git systems)
419498
- [ ] add pre-push hook for validation against best practice, JSHint and customisable rule sets
420-
- [ ] allow saving complete record as XML (via search tool)
499+
- [x] allow saving complete record as XML (via search tool)
421500
- [ ] when an update conflict has been detected write out the remote file and launch a diff app (command line "diff" or mac OS XCode "FileMerge" via "`opendiff <left> <right>`") for the user to help resolve the differences
422501
- [ ] allow upload override of server record if the user has made a merge of remote and local data
423502
- [ ] split out components into separate modules (eg, sn-search, sn-sync, sn-rest)

app.config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
"query": "active=true^sys_created_on>javascript:gs.dateGenerate('2015-03-25','23:59:59')",
3535
"records_per_search": "1",
3636
"download": true
37+
},
38+
"script-includes-plus": {
39+
"table": "sys_script_include",
40+
"query": "active=true^sys_created_on>javascript:gs.dateGenerate('2015-03-25','23:59:59')",
41+
"records_per_search": "1",
42+
"download": true,
43+
"full_record": true
3744
}
3845
},
3946

0 commit comments

Comments
 (0)