A few weeks ago, I shared a spectacular week with my new team in Hyderabad, India. We shared a fun-filled week geeking out on integration and application development on the ServiceNow platform. These folks are going to have a lot of fun with the types of projects coming our way.
Within the next few months the world will see how the built-in ServiceNow editors have continued to get more and more functional and feature rich (oooh….can’t wait for that Geneva release!). However, some people continue to use traditional native text editors for typing their code. After spending time with my teams both in the US and in India, I continued to see a large amount of copy-paste action happening from text editors into the ServiceNow browser windows, I decided that I needed to resurrect my 7 year old Python skills and update the ever-useful ServiceNow plugin for the Sublime Text editor which was original written by some talented friends at Fruition Partners (Original Sublime Text Plugin). I actually wrote about this plugin last year in “Using the SublimeEditor to write ServiceNow code“, but decided that it needed a little updating.
I have forked the original Fruition version of the plugin and have created a version that has the following enhancements:
Support for Sublime Text 3
One of the first things people ask me when I have tried to introduce the ServiceNow plugin for Sublime is whether it works with Sublime 3. I have always had to tell them that unfortunately they would be sticking with Sublime Text 2 if they wanted to use the plugin. Well, no more! The ServcieNow plugging or Sublime now works on both Sublime 2 as well as Sublime 3.
Enhanced Messaging to the End User
In the past, if there was a connection or other error during the sync process, an error would get output to the log behind the scenes, but the end user would have no clue that their changes were never uploaded to the server. I have added modal dialog boxes that will notify the user when there are such errors and provide some basic text around the error. More detailed text can be found in the behind-the-scenes debug log still as well. This will provide better user confidence in their use of the plugin.
Conflict Detection
This feature is the one I am most excited about as it fixes one of the biggest impediments for me in using this plugin in a team environment. In the past, if people were to change the source within the ServiceNow instance between the times when I was saving my version within the sublime editor, their changes would be overwritten by my copy. I have enhanced the plugin such that it will pull the current instance version of the data and do a conflict detection routine before it tries to update the server. If there appears to be a mismatch of any kind, the save action will be aborted and the user will be notified that they need to resolve the differences between the instance version of the data and their own. This should help prevent Sublime users from inadvertently overwriting important changes that are done within the instance on the same record.
To get the newest version of this plugin, please visit: Enhanced Sublime Text Plugin for ServiceNow
Instructions
The instructions for using this plugin are the same as the original plugin. At the top of the record text in Sublime, add a comment section to indicate where the text will be saved. Your comment block will contain three parameters:
- __fileURL – This is the full direct URL to the record. Don’t use the url that leverages “nav_to.do”. Use only the direct URL.
- __fieldName – This is the field that will contain the text you save in your editor. It is the database name for the field, not the label of the field
- __authentication – This is your credentials for that instance in this format: username:password. After the save, the text will be replaced with “STORED”.
A couple of examples of your Sublime Text Comment Block Include:
XML / HTML Fields
1 2 3 4 5 | <!-- // __fileURL = https://myinstance.service-now.com/sys_ui_page.do?sys_id=2d8dcb5e6f2d060009125ee44b3ee4b9 // __fieldName = html // __authentication = STORED --> |
Javascript Fields
1 2 3 | // __fileURL = https://myinstance.service-now.com/sys_ui_page.do?sys_id=2d8dcb5e6f2d060009125ee44b3ee4b9 // __fieldName = html // __authentication = STORED |
Video
Updated Sublime Text 3 Plugin for ServiceNow
Hi John,
I love the tool. I found an issue with the script and usernames containing backslashes (our Servicenow is integrated with Active Directory so all our usernames are in the form Domain\Username). The regular expression doesn’t like backslashes. I added a double backslash to the regex which resolves the problem. Line 237 of serviceNowBuild.py. Thanks and keep up the great work!
Below is the new line:
authMatch = re.search(r”__authentication[\W=]*([a-zA-Z0-9:~`\/\!@#$%\^&*()_\-\\;,.]*)”, text)
Regards,
Michael.
Thank you for the update John! I was using this with Sublime 2, but will try it now with Sublime 3. Much appreciated
Michael,
Good suggestion…very common use case. I have added your suggestion to the github version of the plugin.
Thanks!John
BTW, looks like the new authMatch line has the wrong type of quotes in it, causing the script to break.
Great catch John…should have known better than copy and paste from my browser’s comment window directly into the code. Should be fixed now.
Great update here John, this goes hand in hand with the AngularJS framework!
Keep up the superb work!
Thanks
Works like a charm. However, how do I write the client script code in sublime editor? I tried writing below the XML and is NOT working! Please let me know.
Basically, I want to store the script within the client_script field in SN. How do I create the snippet in Sublime?
Thanks,
Ajaz
@Ajaz – Your script header would look something like:
// __fileURL = https://YOURINSTANCE.service-now.com/sys_script_client.do?sys_id=YOUR_CLIENT_SCRIPT_SYS_ID
// __fieldName = script
// __authentication = ENTERUSERNAME:ENTERPASSWORDHERE
John, This is for a UI Page. We have two fields html and client_script. How do we handle both the code in ONE Sublime File?
Thanks again,
Ajaz
@Ajaz, a sublime file is on a field basis only. If you are working on two fields for a form, then you will have two sublime files.
Example:
HTML Field:
<!–
// __fileURL = https://MYINSTANCE.service-now.com/sys_ui_page.do?sys_id=1f5dc5aa5f130100a9ad2572f2b477ed
// __fieldName = html
// __authentication = john.andersen:ENTERPASSWORDHERE
–>
CLIENT_SCRIPT FIELD
// __fileURL = https://MYINSTANCE.service-now.com/sys_ui_page.do?sys_id=1f5dc5aa5f130100a9ad2572f2b477ed
// __fieldName = client_script
// __authentication = john.andersen:ENTERPASSWORDHERE
Awesome. Thanks for a quick response John. Now I am looking for a Sublime autocompletion for Glide API. I found this one https://github.com/jbutz/SublimeText-GlideCompletion and https://github.com/dancigrang/servicenow-autocomplete .
Has anyone investigated using OAUTH to authenticate instead of hard-coding the userid/password?
Plugin download link is broken. Has this been discontinued?
Not sure why it broke, but I have fixed the link.
This looks awesome, but is there an update for this for jakarta? I can’t seem to get my changes to happen when adding my own file url, field name and auth info.