{
  "Service Portal: AngularJS $broadcast": {
    "prefix": "sp-ng-broadcast",
    "body": ["\\$rootScope.\\$broadcast('${1:eventName}', ${2:args});"],
    "description": "AngularJS $broadcast: Dispatches an event name downwards to all child scopes (and their children)"
  },
  "Service Portal: AngularJS Component": {
    "prefix": "sp-ng-component",
    "body": [
      "(function() {",
      "\t'use strict';",
      "",
      "\tvar ${1:componentName} = {",
      "\t\ttemplate: [",
      "\t\t\t'$0'",
      "\t\t].join('')",
      "\t};",
      "",
      "\tangular",
      "\t\t.module('${2:moduleName}')",
      "\t\t.component('${1:componentName}', ${1:componentName});",
      "})();"
    ],
    "description": "AngularJS Component: is a special kind of directive that uses a simpler configuration which is suitable for a component-based application structure"
  },
  "Service Portal: AngularJS Controller": {
    "prefix": "sp-ng-controller",
    "body": [
      "function ${1:Name}Controller() {",
      "\tvar c = this;",
      "",
      "\tc.\\$onInit = function() {$0};",
      "}"
    ],
    "description": "AngularJS Controller: is defined by a JavaScript constructor function that is used to augment the scope"
  },
  "Service Portal: AngularJS $emit": {
    "prefix": "sp-ng-emit",
    "body": ["\\$rootScope.\\$emit('${1:eventName}', ${2:args});"],
    "description": "AngularJS $emit: Dispatches an event name upwards through the scope hierarchy"
  },
  "Service Portal: AngularJS $http": {
    "prefix": "sp-ng-http",
    "body": [
      "\\$http.get('${1:/api/now/table/problem?active=true&sysparm_limit=1}').then(function(response) {",
      "\t${2:c.dataObject} = response.data.result;",
      "});"
    ],
    "description": "AngularJS $http: The $http service is a core AngularJS service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP"
  },
  "Service Portal: GlideUser getDisplayName()": {
    "prefix": "sp-user-getDisplayName",
    "body": ["var ${1:currentUser} = gs.getUser().getDisplayName();"],
    "description": "getDisplayName(): Returns the current user's display name"
  },
  "Service Portal: GlideUser getEmail()": {
    "prefix": "sp-user-getEmail",
    "body": ["var ${1:email} = gs.getUser().getEmail();"],
    "description": "getEmail(): Returns the user's email address"
  },
  "Service Portal: GlideUser getFirstName()": {
    "prefix": "sp-user-getFirstName",
    "body": ["var ${1:firstName} = gs.getUser().getFirstName();"],
    "description": "getFirstName(): Returns the user's first name"
  },
  "Service Portal: GlideUser getID()": {
    "prefix": "sp-user-getID",
    "body": ["var ${1:userID} = gs.getUser().getID();"],
    "description": "getID(): Gets the sys_id of the current user"
  },
  "Service Portal: GlideUser getLastName()": {
    "prefix": "sp-user-getLastName",
    "body": ["var ${1:lastName} = gs.getUser().getLastName();"],
    "description": "getLastName(): Returns the user's last name"
  },
  "Service Portal: GlideUser getUserName()": {
    "prefix": "sp-user-getUserName",
    "body": ["var ${1:username} = gs.getUserName();"],
    "description": "getUserName(): Returns the current user's username"
  },
  "Service Portal: GlideUser hasRole()": {
    "prefix": "sp-user-hasRole",
    "body": ["var ${1:hasRole} = gs.getUser().hasRole('${2:admin}');"],
    "description": "hasRole(): Determines if the current user has the specified role"
  },
  "Service Portal: GlideUser isMemberOf()": {
    "prefix": "sp-user-isMemberOf",
    "body": ["var ${1:isMember} = gs.getUser().isMemberOf('${2:Service Desk}');"],
    "description": "isMemberOf(): Determines if the current user is a member of the specified group"
  },
  "Service Portal: GlideRecord addActiveQuery()": {
    "prefix": "sp-record-addActiveQuery",
    "body": [
      "var inc = new GlideRecord('${1:incident}');",
      "inc.addActiveQuery();",
      "inc.query();",
      "while (inc.next()) {",
      "\t$3",
      "}"
    ],
    "description": "addActiveQuery(): Adds a filter to return active records"
  },
  "Service Portal: GlideRecord addEncodedQuery()": {
    "prefix": "sp-record-addEncodedQuery",
    "body": [
      "var query = '${1:priority=1^ORpriority=2}';",
      "var gr = new GlideRecord('${2:incident}');",
      "gr.addEncodedQuery(query);",
      "gr.query();",
      "while (gr.next()) {",
      "\t$3",
      "}"
    ],
    "description": "addEncodedQuery(): Adds an encoded query to other queries that may have been set"
  },
  "Service Portal: GlideRecord create": {
    "prefix": "sp-record-create",
    "body": ["var gr = new GlideRecord('${1:incident}');"],
    "description": "GlideRecord: Creates an instance of the GlideRecord class for the specified table"
  },
  "Service Portal: GlideRecord deleteMultiple()": {
    "prefix": "sp-record-deleteMultiple",
    "body": [
      "var gr = new GlideRecord('${1:incident}');",
      "gr.addQuery('${2:active}', ${3:false});",
      "gr.deleteMultiple();"
    ],
    "description": "deleteMultiple(): Deletes multiple records that satisfy the query condition"
  },
  "Service Portal: GlideRecord deleteRecord()": {
    "prefix": "sp-record-deleteRecord",
    "body": [
      "var gr = new GlideRecord('${1:incident}');",
      "gr.addQuery('${2:sys_id}', '${3:99ebb4156fa831005be8883e6b3ee4b9}');",
      "gr.query();",
      "gr.next();",
      "gr.deleteRecord();"
    ],
    "description": "deleteRecord(): Deletes the current record"
  },
  "Service Portal: GlideRecord get()": {
    "prefix": "sp-record-get",
    "body": [
      "var gr = new GlideRecord('${1:incident}');",
      "gr.get('${2:bf5a8df9db55d700abd4f9361d961937}');",
      "gs.info(${3:gr.number});"
    ],
    "description": "get(): This method is expected to be used to query for single records"
  },
  "Service Portal: GlideRecord getRowCount()": {
    "prefix": "sp-record-getRowCount",
    "body": [
      "var gr = new GlideRecord('${1:incident}');",
      "gr.query();",
      "gs.info(${2:'Records in incident table: ' + gr.getRowCount()});"
    ],
    "description": "getRowCount(): Retrieves the number of rows in the query result"
  },
  "Service Portal: GlideRecord insert()": {
    "prefix": "sp-record-insert",
    "body": [
      "var gr = new GlideRecord('${1:problem}');",
      "gr.initialize();",
      "gr.${2:short_description} = '${3:Ninja Issue}';",
      "gr.${4:description} = '${5:Ninja attack on CMDB}';",
      "gr.insert();"
    ],
    "description": "insert(): Inserts a new record using the field values that have been set for the current record"
  },
  "Service Portal: GlideRecord setLimit()": {
    "prefix": "sp-record-setLimit",
    "body": [
      "var gr = new GlideRecord('${1:incident}');",
      "gr.orderByDesc('${2:sys_created_on}');",
      "gr.setLimit(${3:10});",
      "gr.query();"
    ],
    "description": "setLimit(): This method is expected to be used to query for single records"
  },
  "Service Portal: GlideRecord update()": {
    "prefix": "sp-record-update",
    "body": [
      "var gr = new GlideRecord('${1:incident}');",
      "gr.get('${2:4c085e2e1324e700c664f8fed144b062}');",
      "gr.${3:category} = '${4:database}';",
      "gr.update();"
    ],
    "description": "update(): Updates the GlideRecord with any changes that have been made"
  },
  "Service Portal: GlideRecord updateMultiple()": {
    "prefix": "sp-record-updateMultiple",
    "body": [
      "var gr = new GlideRecord('${1:incident}')",
      "gr.addQuery('${2:active}', ${3:true});",
      "gr.query();",
      "gr.setValue('${4:state}', ${5:4});",
      "gr.updateMultiple();"
    ],
    "description": "updateMultiple(): Updates each GlideRecord in the list with any changes that have been made"
  },
  "Service Portal: GlideSession getClientIP()": {
    "prefix": "sp-session-getClientIP",
    "body": ["var ${1:clientIP} = gs.getSession().getClientIP();"],
    "description": "getClientIP(): Returns the client IP address"
  },
  "Service Portal: GlideSession getLanguage()": {
    "prefix": "sp-session-getLanguage",
    "body": ["var ${1:language} = gs.getSession().getLanguage();"],
    "description": "getLanguage(): Returns the session's language code"
  },
  "Service Portal: GlideSession isLoggedIn()": {
    "prefix": "sp-session-isLoggedIn",
    "body": ["var ${1:isLoggedIn} = gs.getSession().isLoggedIn();"],
    "description": "isLoggedIn(): Returns true if the user is logged in"
  },
  "Service Portal: AngularJS Module": {
    "prefix": "sp-ng-module",
    "body": [
      "(function() {",
      "\t'use strict';",
      "",
      "\tangular.module('${1:moduleName}', []);",
      "})();"
    ],
    "description": "AngularJS Module: is a global place for creating, registering and retrieving AngularJS modules"
  },
  "Service Portal: AngularJS $on": {
    "prefix": "sp-ng-on",
    "body": [
      "\\$scope.\\$on('${1:eventName}', function(event, args) {",
      "\t$2console.log(args);",
      "});"
    ],
    "description": "AngularJS $on: Listens on events of a given type"
  },
  "Service Portal: AngularJS $onInit": {
    "prefix": "sp-ng-onInit",
    "body": ["c.\\$onInit = function() {", "\t$0", "};"],
    "description": "AngularJS $onInit: Called on each controller after all the controllers on an element have been constructed and had their bindings initialized"
  },
  "Service Portal: AngularJS Service": {
    "prefix": "sp-ng-service",
    "body": [
      "(function() {",
      "\t'use strict';",
      "",
      "\tfunction ${1:serviceName}() {",
      "\t\tvar service = {",
      "\t\t\t${3:getSomething}: ${3:getSomething}",
      "\t\t};",
      "\t\treturn service;",
      "",
      "\t\tfunction ${3:getSomething}() {$0}",
      "\t}",
      "",
      "\tangular",
      "\t\t.module('${2:moduleName}')",
      "\t\t.service('${1:serviceName}', ${1:serviceName});",
      "})();"
    ],
    "description": "AngularJS Service: is a constructor function which is invoked once at runtime and wired together using dependency injection (DI)"
  },
  "Service Portal: spModal alert": {
    "prefix": "sp-modal-alert",
    "body": [
      "function OnAlertController(spModal) {",
      "\tvar c = this;",
      "\tc.${1:onAlert} = ${1:onAlert};",
      "",
      "\tfunction ${1:onAlert}() {",
      "\t\treturn spModal.alert('${2:How do you feel today?}').then(function(answer) {",
      "\t\t\tc.${3:simple} = answer;",
      "\t\t});",
      "\t}",
      "}"
    ],
    "description": "spModal alert: Displays an alert"
  },
  "Service Portal: Script Include": {
    "prefix": "sp-script-include",
    "body": [
      "var ${1:NewInclude} = Class.create();",
      "${1:NewInclude}.prototype = {",
      "\tinitialize: function() {},",
      "\t${2:myFunction}: function() {",
      "\t\t$0",
      "\t},",
      "\ttype: '${1:NewInclude}',",
      "};"
    ],
    "description": "Script includes are used to store JavaScript that runs on the server"
  },
  "Service Portal: spModal confirm": {
    "prefix": "sp-modal-confirm",
    "body": [
      "function OnConfirmController(spModal) {",
      "\tvar c = this;",
      "\tc.onConfirm = onConfirm;",
      "",
      "\tfunction onConfirm() {",
      "\t\tc.confirmed = 'asking';",
      "\t\treturn spModal.confirm('Can you confirm or deny this?').then(function(confirmed) {",
      "\t\t\tc.confirmed = confirmed;",
      "\t\t});",
      "\t}",
      "}"
    ],
    "description": "spModal confirm: Displays a confirmation message"
  },
  "Service Portal: spModal open": {
    "prefix": "sp-modal-open",
    "body": [
      "function OnWidgetController(spModal) {",
      "\tvar c = this;",
      "\tc.onWidget = onWidget;",
      "",
      "\tfunction onWidget(widgetId, widgetInput) {",
      "\t\treturn spModal.open({",
      "\t\t\ttitle: 'Displaying widget ' + widgetId,",
      "\t\t\twidget: widgetId,",
      "\t\t\twidgetInput: widgetInput || {}",
      "\t\t}).then(function() {",
      "\t\t\tconsole.log('widget dismissed');",
      "\t\t});",
      "\t}",
      "}"
    ],
    "description": "spModal open: Opens a modal window with an embedded widget"
  },
  "Service Portal: spModal prompt": {
    "prefix": "sp-modal-prompt",
    "body": [
      "function OnPromptController(spModal) {",
      "\tvar c = this;",
      "\tc.onPrompt = onPrompt;",
      "",
      "\tfunction onPrompt() {",
      "\t\treturn spModal.prompt('Your name please', c.name).then(function(name) {",
      "\t\t\tc.name = name;",
      "\t\t});",
      "\t}",
      "}"
    ],
    "description": "spModal prompt: Displays a prompt for user input"
  },
  "Service Portal: spUtil addErrorMessage": {
    "prefix": "sp-util-addErrorMessage",
    "body": ["spUtil.addErrorMessage('${1:Sample error message}');"],
    "description": "addErrorMessage: Displays a notification error message"
  },
  "Service Portal: spUtil addInfoMessage": {
    "prefix": "sp-util-addInfoMessage",
    "body": ["spUtil.addInfoMessage('${1:Sample info message}');"],
    "description": "addInfoMessage: Displays a notification info message"
  },
  "Service Portal: spUtil addTrivialMessage": {
    "prefix": "sp-util-addTrivialMessage",
    "body": ["spUtil.addTrivialMessage('${1:Sample trivial message}');"],
    "description": "addTrivialMessage: Displays a trivial notification message"
  },
  "Service Portal: spUtil Get Widget": {
    "prefix": "sp-util-get",
    "body": [
      "function ${1:Test}Controller(spUtil) {",
      "\tvar c = this;",
      "\tc.${2:getWidget} = ${2:getWidget};",
      "",
      "\tc.\\$onInit = function() {",
      "\t\t${2:getWidget}();",
      "\t};",
      "",
      "\tfunction ${2:getWidget}() {",
      "\t\treturn spUtil.get('${3:widget-cool-clock}').then(function(response) {",
      "\t\t\tc.${4:exampleWidget} = response;",
      "\t\t});",
      "\t}",
      "}"
    ],
    "description": "Embedded widget: Use spUtil.get() to get a widget model in the client script"
  },
  "Service Portal: spUtil Get Widget with Options": {
    "prefix": "sp-util-get-options",
    "body": [
      "function ${1:Test}Controller(spUtil) {",
      "\tvar c = this;",
      "\tc.${2:getWidget} = ${2:getWidget};",
      "",
      "\tc.\\$onInit = function() {",
      "\t\t${2:getWidget}();",
      "\t};",
      "",
      "\tfunction ${2:getWidget}() {",
      "\t\treturn spUtil.get('${3:widget-cool-clock}', {${4:sys_id}: '${5:example_sys_id}'}).then(function(response) {",
      "\t\t\tc.${6:exampleWidget} = response;",
      "\t\t});",
      "\t}",
      "}"
    ],
    "description": "Embedded widget: Use spUtil.get() to get a widget model in the client script"
  },
  "Service Portal: spUtil Record Watch": {
    "prefix": "sp-util-record-watch",
    "body": [
      "spUtil.recordWatch(\\$scope, '${1:incident}', '${2:active=true}', function(name, data) {",
      "\t$3console.log(name);",
      "\t$4console.log(data);",
      "});"
    ],
    "description": "Record Watch: A tool that allows a widget developer to respond to table updates in real-time"
  }
}
