Service Portal Snippets for VS Code
Tags: servicenow, serviceportal, vscode
Published: 2021-07-20 14:01:33

---
title: Service Portal Snippets for VS Code
published: true
description: A collection of handy Service Portal snippets for VS Code.
tags: servicenow, serviceportal, vscode
// cover_image: 
---

Interested in speeding up your ServiceNow development workflow in VS Code? Sure, why not you say. Ok, let's move forward. :rocket:

The [Service Portal Snippets](https://marketplace.visualstudio.com/items?itemName=stevengregory.service-portal-snippets) extension for VS Code adds a handy collection of Service Portal snippets to your ServiceNow development workflow. Code snippets make it easy to streamline your development workflow, accelerate efficiency and implement proven & tested patterns of best practice on the fly.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gywoxfmlo2r3rutz7m38.gif)

## Installation


To install the [Service Portal Snippets](https://marketplace.visualstudio.com/items?itemName=stevengregory.service-portal-snippets) extension, do so in the usual methods. This may be obvious, but if not see [Install Visual Studio Code extensions](https://code.visualstudio.com/learn/get-started/extensions).

Or install via the command line (my preference).

```bash
code --install-extension stevengregory.service-portal-snippets
```

## Usage

To generate a snippet, type part of the snippet and press enter.

To find a list of snippet commands, checkout out the [vscode-service-portal-snippets](https://github.com/stevengregory/vscode-service-portal-snippets#usage) repository on GitHub.

> ProTip: type the snippet without dashes to activate IntelliSense. 😎

## Examples

On a JavaScript file, to generate a snippet for getting the current user's display name using GlideUser, type `sp-user-getDisplayName`.

```javascript
var currentUser = gs.getUser().getDisplayName();
```

To create a snippet for getting active records using GlideRecord, type `sp-record-addactivequery`.

```javascript
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.query();
while (inc.next()) {
  
}
```

*Enter AngularJS & Service Portal*. To generate a widget client script controller with an `$onInit` lifecycle hook, type `sp-ng-controller`.

```javascript
function NinjaController() {
  var c = this;

  c.$onInit = function() {};
}
```

On an HTML file, to create an `ng-repeat` with an `orderBy` filter, type `sp-ng-repeat-orderby`.

```html
<div ng-repeat="item in c.items | orderBy: 'order'"></div>
```

On a UI Script, to create an AngularJS service like a boss, type `sp-ng-service`.

```javascript
(function() {
  'use strict';

  function serviceName() {
    var service = {
      getSomething: getSomething
    };
    return service;

    function getSomething() {}
  }

  angular
    .module('moduleName')
    .service('serviceName', serviceName);
})();
```

And there are many more. Cool right?! :thumbsup:

## Contributing

This is an open source project and still a work in progress, so feel free to open up a pull request and contribute. Also, if you have any suggestions or feedback, please send them my way — thanks!

> "Teamwork makes the Dreamwork!" - [Bill McDermott](https://twitter.com/BillRMcDermott)