Visual Studio Code Snippets for common ServiceNow Syntax Macros
We are using Visual Studio 2015 for writing our ServiceNow scripts. The new "Studio" IDE in Geneva looks very promising, and we are considering switching to it. For now, the fact that we VS integrates tightly with TFS (and that we don't want to lose versions in Dev when we clone down from Production), is compelling.
Visual Studio uses XML Snippet files to accomplish what ServiceNow natively handles via Syntax Editor Macros
For the benefit of any other Visual Studio users out there, here are some helpful Visual Studio Snippets for inserting ServiceNow code quickly:
Snippet XML "grins.snippet" for the insert a GlideRecord template.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
Expansion
Insert GlideRecord
Trey Carroll
Template for inserting a GlideRecord record
grins
TableName
Replace with a SN table name.
Table name goes here.
UpdateColumnName
Replace with a SN column name to update.
UpdateColumnName
UpdateColumnValue
Replace with a column value.
UpdateColumnValue
<![CDATA[
var gr = new GlideRecord('$TableName$');
gr.Initialize();
gr.$UpdateColumnName$ = '$UpdateColumnValue$';
gr.insert();
]]>
Now open VS's Code Snippet Manager using Ctrl-K, Ctrl-B (or use the menus to browse to Tools->Code Snippet Manager)
Browse to the "grins.snippet" file you saved previously and and import it into your "My Code Snippets" folder.
Now in Visual Studio in a JavaScript file...
Typing the shortcut "grins" and tabbing will add this code snippet to the JavaScript file.
You can tab through the highlighted values filling in the placeholder text. It's actually a very nice solution.
I have attached .snippet files for 4 common templates:
1) Inserting a record.
2) Updating a single record.
3) Updating multiple records.
4) Querying via an encoded query.
G_d speed,
Trey Carroll
https://www.servicenow.com/community/north-texas-snug/visual-studio-code-snippets-for-common-servicenow-syntax-macros/ba-p/2285466