Update (5/2/16): Got the code on github for whoever is interested. Pull requests are welcome. github repository
I think many people had given up hope but I decided last night to finally get to creating my ServiceNow Sync plugin for Sublime Text 3. I also took the opportunity to clean up some bugs and introduce diffing.
Open the Console (Ctrl+`) and paste the following code and run
import urllib.request,os,hashlib; pf = 'ServiceNow Sync.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://snaug.com/snowsync/' + pf.replace(' ', '%20')).read(); open(os.path.join( ipp, pf), 'wb' ).write(by)
You may need to restart Sublime to see the changes.
If everything worked correctly you should get a new “ServiceNow Sync” menu.
You can install manually by placing this file in the Installed Packages folder for ST3.
Creating a Project
To start using the plugin you need to be in a Folder View, so go to File > Open Folder.
If you try to use the plugin otherwise it will give you an error. It used to just crash, so that’s an improvement.
Next you will want to create the connection to a ServiceNow instance. Go to ‘ServiceNow Sync’ then ‘Connect To ServiceNow’
A prompt will open up at the bottom of the screen asking you to enter first your instance name (exclude the .service-now.com).
instance example if your instance url is `https://snaug.service-now.com` then you would put “snaug”.
Next it will prompt for your username and password. Be careful entering the password as the text is not hidden.
This will create a service-now.json file in your folder.
After this I will usually just try “Test Connection” to make sure everything is working.
To sync a table you first start by going to the “Sync Table” option in “ServiceNow Sync”. This will pull up a list of tables which you can search through.
Once a table is selected you will be prompted (at the very bottom) to provide some details about what you want to sync.
The first prompt will ask you for the folder name, this usually matches the table but can be anything.
After that you will be asked some details about the content. The first option is the name field, which is almost always “name” this will be used as the local file name as well.
The script field is the field which should be used as the contents of the file. Usually this is “script” as in Business Rules or Script Includes but it could also be: “html” for UI Pages, “xml” for UI Macros”, “programmatic_content” for Dynamic Content Blocks and so on.
In fact this can be any field on a record.
The last option is the file extension. This should match the content, such as “.js”, “.html” or “.css”. The correct extension will give you the appropriate highlighting.
Once complete a folder will be created matching
One note, it is possible to sync the same table multiple times. You can create several folder that all map to the same table, they will not interfere with each other. You can also use the same technique to sync to different fields, for instance UI pages can have several folders one for HTML, one for Client Script and one for Processing Script.
After syncing a table you can now sync files for that table. To do this just right click on the folder and select ‘Sync File’. This will retrieve a list of files, once you select the file from the list it will be created locally.
From time to time it may be necessary to resync the same file to a different record in ServiceNow. In each table folder there is a service-now.json file which has a record of all the files and their sys ids in ServiceNow. You can remove a particular entry or change it.
Saving a file to a record is all part of the Save process. Once you save the file will be automatically uploaded to ServiceNow.
Creating a local file and saving the file will create a record in ServiceNow. It will use the file name as the name in ServiceNow.
No. That’s nuts. Deleting local copies WILL NOT delete anything on your instance. Deleting records in ServiceNow will not delete the local files.
This may save you one day, it already has saved me multiple times.
If you are working in an environment with multiple developers it is very important not to overwrite others work. To prevent this the ServiceNow Sync plugin will check for differences between the local and remote copy. If it finds differences it will alert you and ask what to do.
If you are saving, you will be prompted to Overwrite the Remote copy or view the differences.
You may also check for updates by right-clicking on a file and selecting “Compare to Server”. If there are differences you can Overwrite your local copy or view the differences.
Opening A ServiceNow Record
One other quick feature, if you are in the body of a file, you can right click and select ‘Open ServiceNow Record’ to quickly open the record in the instance.
It is possible to share an entire folder with co-workers. I actually check the whole folder into Git. The only thing you want to make sure is to not check in the “service-now.json” in the root folder as this has the authentication information in it. All the sub-folder JSON files are ok to check in or share.
Known Issues and Enhancements
Unicode Characters break the file diffing. Fixed
At some point I would like to add the ability to set an update set on the system, in fact the menu item is already there but disabled. Some day…
Any other issues please reach out to me directly until I can get this on Github.