- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
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">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Insert GlideRecord</Title>
<Author>Trey Carroll</Author>
<Description>Template for inserting a GlideRecord record</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>grins</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>TableName</ID>
<ToolTip>Replace with a SN table name.</ToolTip>
<Default>Table name goes here.</Default>
</Literal>
<Literal>
<ID>UpdateColumnName</ID>
<ToolTip>Replace with a SN column name to update.</ToolTip>
<Default>UpdateColumnName</Default>
</Literal>
<Literal>
<ID>UpdateColumnValue</ID>
<ToolTip>Replace with a column value.</ToolTip>
<Default>UpdateColumnValue</Default>
</Literal>
</Declarations>
<Code Language="JavaScript">
<![CDATA[
var gr = new GlideRecord('$TableName$');
gr.Initialize();
gr.$UpdateColumnName$ = '$UpdateColumnValue$';
gr.insert();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.