├── .gitattributes ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── images ├── icon.png └── use-extension.gif ├── jsconfig.json ├── package-lock.json ├── package.json └── snippets ├── html.json └── javascript.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behavior to automatically normalize line endings. 2 | * text=auto 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .vscode-test/ 3 | *.vsix 4 | .DS_Store 5 | yarn-error.log -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ] 16 | }, 17 | { 18 | "name": "Extension Tests", 19 | "type": "extensionHost", 20 | "request": "launch", 21 | "runtimeExecutable": "${execPath}", 22 | "args": [ 23 | "--extensionDevelopmentPath=${workspaceFolder}", 24 | "--extensionTestsPath=${workspaceFolder}/test" 25 | ] 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | test/** 4 | .gitignore 5 | jsconfig.json 6 | vsc-extension-quickstart.md 7 | .eslintrc.json 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Service Portal Snippets Changelog 2 | 3 | 4 | 5 | ## 1.0.5 (2023-02-28) 6 | 7 | - README update 8 | - Package update 9 | 10 | 11 | 12 | ## 1.0.4 (2021-02-25) 13 | 14 | - README update 15 | - Package update 16 | 17 | 18 | 19 | ## 1.0.3 (2020-04-26) 20 | 21 | - Added script include snippet 22 | - Package updates 23 | - README clean-up 24 | 25 | 26 | 27 | ## 1.0.2 (2018-09-21) 28 | 29 | - Added placeholders to alert snippet 30 | - Quick copy update on README 31 | 32 | 33 | 34 | ## 1.0.1 (2018-09-19) 35 | 36 | - Fixed issue with \$ not escaping 37 | 38 | 39 | 40 | ## 1.0.0 (2018-09-19) 41 | 42 | - Added snippets for 43 | - HTML 44 | - Client 45 | - Server 46 | - UI Scripts 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Steven Gregory 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Service Portal Snippets for VS Code 2 | 3 | This extension for Visual Studio Code adds a handy collection of ServiceNow [Service Portal](https://www.servicenow.com/products/service-portal.html) snippets. The snippets adhere to best practice by following the [Service Portal: Style Guide](https://github.com/stevengregory/service-portal-style-guide). 4 | 5 | ![Use Extension](images/use-extension.gif) 6 | 7 | See the [CHANGELOG](CHANGELOG.md) for the latest changes. 8 | 9 | ## Usage 10 | 11 | To generate a snippet, simply type part of the snippet and press `enter`. 12 | 13 | ### HTML Snippets 14 | 15 | | Snippet | Purpose | 16 | | ----------------------- | ------------------------------------- | 17 | | `sp-ng-class-attribute` | `ng-class` with attribute | 18 | | `sp-ng-class-css` | `ng-class` with CSS class | 19 | | `sp-ng-if` | `ng-if` | 20 | | `sp-ng-include` | `ng-include` | 21 | | `sp-ng-repeat` | `ng-repeat` | 22 | | `sp-ng-repeat-combo` | `ng-repeat` with orderBy and track by | 23 | | `sp-ng-repeat-orderBy` | `ng-repeat` with orderBy | 24 | | `sp-ng-repeat-track-by` | `ng-repeat` with track by | 25 | | `sp-modal-alert` | Displays an alert | 26 | | `sp-modal-confirm` | Displays a confirmation message | 27 | | `sp-modal-open` | Opens a modal window using options | 28 | | `sp-modal-prompt` | Displays a prompt for user input | 29 | | `sp-tag-embed-widget` | Embed a widget using `` | 30 | | `sp-util-embed-widget` | Embed a widget using `` | 31 | 32 | ### Client Snippets 33 | 34 | | Snippet | Purpose | 35 | | --------------------------- | ----------------------------------------- | 36 | | `sp-ng-broadcast` | `$broadcast` | 37 | | `sp-ng-controller` | Creates a client controller | 38 | | `sp-ng-emit` | `$emit` | 39 | | `sp-ng-http` | `$http` | 40 | | `sp-ng-on` | `$on` | 41 | | `sp-ng-onInit` | `$onInit` | 42 | | `sp-modal-alert` | Displays an alert | 43 | | `sp-modal-confirm` | Displays a confirmation message | 44 | | `sp-modal-open` | Opens a modal window with embedded widget | 45 | | `sp-modal-prompt` | Displays a prompt for user input | 46 | | `sp-util-addErrorMessage` | Displays a notification error message | 47 | | `sp-util-addInfoMessage` | Displays a notification info message | 48 | | `sp-util-addTrivialMessage` | Displays a trivial notification message | 49 | | `sp-util-get` | Embed a widget in the client script | 50 | | `sp-util-get-options` | Embed a widget with options | 51 | | `sp-util-record-watch` | Tool to capture real-time table updates | 52 | 53 | ### Server Snippets 54 | 55 | | Snippet | Purpose | 56 | | --------------------------- | ----------------------------------------- | 57 | | `sp-record-addActiveQuery` | Adds a filter to return active records | 58 | | `sp-record-addEncodedQuery` | Adds an encoded query to other queries | 59 | | `sp-record-create` | Creates a GlideRecord class for a table | 60 | | `sp-record-deleteMultiple` | Deletes multiple records | 61 | | `sp-record-deleteRecord` | Deletes the current record | 62 | | `sp-record-get` | A method used to query for single record | 63 | | `sp-record-getRowCount` | Get the number of rows for a query result | 64 | | `sp-record-insert` | Inserts a new record | 65 | | `sp-record-setLimit` | The maximum number of records to fetch | 66 | | `sp-record-update` | Updates the current record | 67 | | `sp-record-updateMultiple` | Updates multiple records | 68 | | `sp-session-getClientIP` | Returns the client IP address | 69 | | `sp-session-getLanguage` | Returns the session's language code | 70 | | `sp-session-isLoggedIn` | Returns true if the user is logged in | 71 | | `sp-user-getDisplayName` | Get the current user's display name | 72 | | `sp-user-getEmail` | Get the user's email address | 73 | | `sp-user-getFirstName` | Get the user's first name | 74 | | `sp-user-getID` | Get the sys_id of the current user | 75 | | `sp-user-getLastName` | Get the user's last name | 76 | | `sp-user-getUserName` | Get the user's username | 77 | | `sp-user-hasRole` | Determines if a user has a specified role | 78 | | `sp-user-isMemberOf` | Checks if the user is a member of a group | 79 | 80 | ### UI Script Snippets 81 | 82 | | Snippet | Purpose | 83 | | ----------------- | ------------------------------ | 84 | | `sp-ng-component` | Creates an AngularJS component | 85 | | `sp-ng-module` | Creates an AngularJS module | 86 | | `sp-ng-service` | Creates an AngularJS service | 87 | 88 | ### Script Includes 89 | 90 | | Snippet | Purpose | 91 | | ------------------- | ------------------------ | 92 | | `sp-script-include` | Creates a script include | 93 | 94 | ## Pro Tip 95 | 96 | Simply type the snippet without dashes to activate IntelliSense. 97 | 98 | ## License 99 | 100 | [MIT License](LICENSE) 101 | -------------------------------------------------------------------------------- /images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevengregory/vscode-service-portal-snippets/63b4b080fe13aa2a8d234131003bfd19d09d7fc4/images/icon.png -------------------------------------------------------------------------------- /images/use-extension.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevengregory/vscode-service-portal-snippets/63b4b080fe13aa2a8d234131003bfd19d09d7fc4/images/use-extension.gif -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "checkJs": true /* Typecheck .js files. */, 6 | "lib": ["es6"] 7 | }, 8 | "exclude": ["node_modules"] 9 | } 10 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "service-portal-snippets", 3 | "version": "1.0.5", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "service-portal-snippets", 9 | "version": "1.0.5", 10 | "hasInstallScript": true, 11 | "license": "MIT", 12 | "devDependencies": { 13 | "@types/node": "^13.13.52", 14 | "@types/vscode": "^1.75.1", 15 | "typescript": "^3.9.10" 16 | }, 17 | "engines": { 18 | "vscode": "^1.75.1" 19 | } 20 | }, 21 | "node_modules/@types/node": { 22 | "version": "13.13.52", 23 | "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.52.tgz", 24 | "integrity": "sha512-s3nugnZumCC//n4moGGe6tkNMyYEdaDBitVjwPxXmR5lnMG5dHePinH2EdxkG3Rh1ghFHHixAG4NJhpJW1rthQ==", 25 | "dev": true 26 | }, 27 | "node_modules/@types/vscode": { 28 | "version": "1.75.1", 29 | "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.75.1.tgz", 30 | "integrity": "sha512-emg7wdsTFzdi+elvoyoA+Q8keEautdQHyY5LNmHVM4PTpY8JgOTVADrGVyXGepJ6dVW2OS5/xnLUWh+nZxvdiA==", 31 | "dev": true 32 | }, 33 | "node_modules/typescript": { 34 | "version": "3.9.10", 35 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", 36 | "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", 37 | "dev": true, 38 | "bin": { 39 | "tsc": "bin/tsc", 40 | "tsserver": "bin/tsserver" 41 | }, 42 | "engines": { 43 | "node": ">=4.2.0" 44 | } 45 | } 46 | }, 47 | "dependencies": { 48 | "@types/node": { 49 | "version": "13.13.52", 50 | "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.52.tgz", 51 | "integrity": "sha512-s3nugnZumCC//n4moGGe6tkNMyYEdaDBitVjwPxXmR5lnMG5dHePinH2EdxkG3Rh1ghFHHixAG4NJhpJW1rthQ==", 52 | "dev": true 53 | }, 54 | "@types/vscode": { 55 | "version": "1.75.1", 56 | "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.75.1.tgz", 57 | "integrity": "sha512-emg7wdsTFzdi+elvoyoA+Q8keEautdQHyY5LNmHVM4PTpY8JgOTVADrGVyXGepJ6dVW2OS5/xnLUWh+nZxvdiA==", 58 | "dev": true 59 | }, 60 | "typescript": { 61 | "version": "3.9.10", 62 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", 63 | "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", 64 | "dev": true 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "service-portal-snippets", 3 | "displayName": "Service Portal Snippets", 4 | "description": "A collection of ServiceNow Service Portal snippets", 5 | "version": "1.0.5", 6 | "publisher": "stevengregory", 7 | "icon": "images/icon.png", 8 | "license": "MIT", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/stevengregory/vscode-service-portal-snippets.git" 12 | }, 13 | "engines": { 14 | "vscode": "^1.75.1" 15 | }, 16 | "categories": [ 17 | "Snippets" 18 | ], 19 | "keywords": [ 20 | "ServiceNow", 21 | "Service Portal", 22 | "AngularJS", 23 | "Snippet" 24 | ], 25 | "contributes": { 26 | "snippets": [ 27 | { 28 | "language": "html", 29 | "path": "./snippets/html.json" 30 | }, 31 | { 32 | "language": "javascript", 33 | "path": "./snippets/javascript.json" 34 | } 35 | ] 36 | }, 37 | "scripts": { 38 | "postinstall": "node ./node_modules/vscode/bin/install", 39 | "publish": "vsce publish" 40 | }, 41 | "devDependencies": { 42 | "@types/node": "^13.13.52", 43 | "@types/vscode": "^1.75.1", 44 | "typescript": "^3.9.10" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /snippets/html.json: -------------------------------------------------------------------------------- 1 | { 2 | "Service Portal: AngularJS ngClass with attribute": { 3 | "prefix": "sp-ng-class-attribute", 4 | "body": ["

Example

"], 5 | "description": "AngularJS ngClass: is a directive which allows you to dynamically set CSS classes on an HTML element by data binding an expression that represents all classes to be added" 6 | }, 7 | "Service Portal: AngularJS ngClass with CSS class": { 8 | "prefix": "sp-ng-class-css", 9 | "body": ["

Example

"], 10 | "description": "AngularJS ngClass: is a directive which allows you to dynamically set CSS classes on an HTML element by data binding an expression that represents all classes to be added" 11 | }, 12 | "Service Portal: AngularJS ngIf": { 13 | "prefix": "sp-ng-if", 14 | "body": ["
"], 15 | "description": "AngularJS ngIf: is a directive which removes or recreates a portion of the DOM tree based on an {expression}" 16 | }, 17 | "Service Portal: AngularJS ngInclude": { 18 | "prefix": "sp-ng-include", 19 | "body": ["
"], 20 | "description": "AngularJS ngInclude: is a directive which fetches, compiles and includes an external HTML fragment" 21 | }, 22 | "Service Portal: AngularJS ngRepeat": { 23 | "prefix": "sp-ng-repeat", 24 | "body": ["
"], 25 | "description": "AngularJS ngRepeat: is a directive which iterates over a collection" 26 | }, 27 | "Service Portal: AngularJS ngRepeat combo with orderBy and track by": { 28 | "prefix": "sp-ng-repeat-combo", 29 | "body": ["
"], 30 | "description": "AngularJS ngRepeat: is a directive which iterates over a collection; with a combo orderBy filter and tracking expression" 31 | }, 32 | "Service Portal: AngularJS ngRepeat with orderBy": { 33 | "prefix": "sp-ng-repeat-orderBy", 34 | "body": ["
"], 35 | "description": "AngularJS ngRepeat: is a directive which iterates over a collection; with an orderBy filter" 36 | }, 37 | "Service Portal: AngularJS ngRepeat with track by": { 38 | "prefix": "sp-ng-repeat-track-by", 39 | "body": ["
"], 40 | "description": "AngularJS ngRepeat: is a directive which iterates over a collection; with an added tracking expression" 41 | }, 42 | "Service Portal: spModal alert": { 43 | "prefix": "sp-modal-alert", 44 | "body": [""], 45 | "description": "spModal alert: Displays an alert" 46 | }, 47 | "Service Portal: spModal confirm": { 48 | "prefix": "sp-modal-confirm", 49 | "body": [ 50 | "", 51 | "{{${3:c.confirmed}}}" 52 | ], 53 | "description": "spModal confirm: Displays a confirmation message" 54 | }, 55 | "Service Portal: spModal open": { 56 | "prefix": "sp-modal-open", 57 | "body": [""], 58 | "description": "spModal open: Opens a modal window using options" 59 | }, 60 | "Service Portal: spModal prompt": { 61 | "prefix": "sp-modal-prompt", 62 | "body": [ 63 | "", 64 | "
${4:You answered} ${5:{{c.name}}}
" 65 | ], 66 | "description": "spModal prompt: Displays a prompt for user input" 67 | }, 68 | "Service Portal: Embedded widget": { 69 | "prefix": "sp-tag-embed-widget", 70 | "body": [""], 71 | "description": "Embedded widget: Use the element to embed a widget in an HTML template. Pass in the ID of the widget you are trying to embed as a parameter" 72 | }, 73 | "Service Portal: spUtil with embedded widget": { 74 | "prefix": "sp-util-embed-widget", 75 | "body": [""], 76 | "description": "Embedded widget: Use the element along with the client spUtil utility method to embed a widget in an HTML template" 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /snippets/javascript.json: -------------------------------------------------------------------------------- 1 | { 2 | "Service Portal: AngularJS $broadcast": { 3 | "prefix": "sp-ng-broadcast", 4 | "body": ["\\$rootScope.\\$broadcast('${1:eventName}', ${2:args});"], 5 | "description": "AngularJS $broadcast: Dispatches an event name downwards to all child scopes (and their children)" 6 | }, 7 | "Service Portal: AngularJS Component": { 8 | "prefix": "sp-ng-component", 9 | "body": [ 10 | "(function() {", 11 | "\t'use strict';", 12 | "", 13 | "\tvar ${1:componentName} = {", 14 | "\t\ttemplate: [", 15 | "\t\t\t'$0'", 16 | "\t\t].join('')", 17 | "\t};", 18 | "", 19 | "\tangular", 20 | "\t\t.module('${2:moduleName}')", 21 | "\t\t.component('${1:componentName}', ${1:componentName});", 22 | "})();" 23 | ], 24 | "description": "AngularJS Component: is a special kind of directive that uses a simpler configuration which is suitable for a component-based application structure" 25 | }, 26 | "Service Portal: AngularJS Controller": { 27 | "prefix": "sp-ng-controller", 28 | "body": [ 29 | "function ${1:Name}Controller() {", 30 | "\tvar c = this;", 31 | "", 32 | "\tc.\\$onInit = function() {$0};", 33 | "}" 34 | ], 35 | "description": "AngularJS Controller: is defined by a JavaScript constructor function that is used to augment the scope" 36 | }, 37 | "Service Portal: AngularJS $emit": { 38 | "prefix": "sp-ng-emit", 39 | "body": ["\\$rootScope.\\$emit('${1:eventName}', ${2:args});"], 40 | "description": "AngularJS $emit: Dispatches an event name upwards through the scope hierarchy" 41 | }, 42 | "Service Portal: AngularJS $http": { 43 | "prefix": "sp-ng-http", 44 | "body": [ 45 | "\\$http.get('${1:/api/now/table/problem?active=true&sysparm_limit=1}').then(function(response) {", 46 | "\t${2:c.dataObject} = response.data.result;", 47 | "});" 48 | ], 49 | "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" 50 | }, 51 | "Service Portal: GlideUser getDisplayName()": { 52 | "prefix": "sp-user-getDisplayName", 53 | "body": ["var ${1:currentUser} = gs.getUser().getDisplayName();"], 54 | "description": "getDisplayName(): Returns the current user's display name" 55 | }, 56 | "Service Portal: GlideUser getEmail()": { 57 | "prefix": "sp-user-getEmail", 58 | "body": ["var ${1:email} = gs.getUser().getEmail();"], 59 | "description": "getEmail(): Returns the user's email address" 60 | }, 61 | "Service Portal: GlideUser getFirstName()": { 62 | "prefix": "sp-user-getFirstName", 63 | "body": ["var ${1:firstName} = gs.getUser().getFirstName();"], 64 | "description": "getFirstName(): Returns the user's first name" 65 | }, 66 | "Service Portal: GlideUser getID()": { 67 | "prefix": "sp-user-getID", 68 | "body": ["var ${1:userID} = gs.getUser().getID();"], 69 | "description": "getID(): Gets the sys_id of the current user" 70 | }, 71 | "Service Portal: GlideUser getLastName()": { 72 | "prefix": "sp-user-getLastName", 73 | "body": ["var ${1:lastName} = gs.getUser().getLastName();"], 74 | "description": "getLastName(): Returns the user's last name" 75 | }, 76 | "Service Portal: GlideUser getUserName()": { 77 | "prefix": "sp-user-getUserName", 78 | "body": ["var ${1:username} = gs.getUserName();"], 79 | "description": "getUserName(): Returns the current user's username" 80 | }, 81 | "Service Portal: GlideUser hasRole()": { 82 | "prefix": "sp-user-hasRole", 83 | "body": ["var ${1:hasRole} = gs.getUser().hasRole('${2:admin}');"], 84 | "description": "hasRole(): Determines if the current user has the specified role" 85 | }, 86 | "Service Portal: GlideUser isMemberOf()": { 87 | "prefix": "sp-user-isMemberOf", 88 | "body": ["var ${1:isMember} = gs.getUser().isMemberOf('${2:Service Desk}');"], 89 | "description": "isMemberOf(): Determines if the current user is a member of the specified group" 90 | }, 91 | "Service Portal: GlideRecord addActiveQuery()": { 92 | "prefix": "sp-record-addActiveQuery", 93 | "body": [ 94 | "var inc = new GlideRecord('${1:incident}');", 95 | "inc.addActiveQuery();", 96 | "inc.query();", 97 | "while (inc.next()) {", 98 | "\t$3", 99 | "}" 100 | ], 101 | "description": "addActiveQuery(): Adds a filter to return active records" 102 | }, 103 | "Service Portal: GlideRecord addEncodedQuery()": { 104 | "prefix": "sp-record-addEncodedQuery", 105 | "body": [ 106 | "var query = '${1:priority=1^ORpriority=2}';", 107 | "var gr = new GlideRecord('${2:incident}');", 108 | "gr.addEncodedQuery(query);", 109 | "gr.query();", 110 | "while (gr.next()) {", 111 | "\t$3", 112 | "}" 113 | ], 114 | "description": "addEncodedQuery(): Adds an encoded query to other queries that may have been set" 115 | }, 116 | "Service Portal: GlideRecord create": { 117 | "prefix": "sp-record-create", 118 | "body": ["var gr = new GlideRecord('${1:incident}');"], 119 | "description": "GlideRecord: Creates an instance of the GlideRecord class for the specified table" 120 | }, 121 | "Service Portal: GlideRecord deleteMultiple()": { 122 | "prefix": "sp-record-deleteMultiple", 123 | "body": [ 124 | "var gr = new GlideRecord('${1:incident}');", 125 | "gr.addQuery('${2:active}', ${3:false});", 126 | "gr.deleteMultiple();" 127 | ], 128 | "description": "deleteMultiple(): Deletes multiple records that satisfy the query condition" 129 | }, 130 | "Service Portal: GlideRecord deleteRecord()": { 131 | "prefix": "sp-record-deleteRecord", 132 | "body": [ 133 | "var gr = new GlideRecord('${1:incident}');", 134 | "gr.addQuery('${2:sys_id}', '${3:99ebb4156fa831005be8883e6b3ee4b9}');", 135 | "gr.query();", 136 | "gr.next();", 137 | "gr.deleteRecord();" 138 | ], 139 | "description": "deleteRecord(): Deletes the current record" 140 | }, 141 | "Service Portal: GlideRecord get()": { 142 | "prefix": "sp-record-get", 143 | "body": [ 144 | "var gr = new GlideRecord('${1:incident}');", 145 | "gr.get('${2:bf5a8df9db55d700abd4f9361d961937}');", 146 | "gs.info(${3:gr.number});" 147 | ], 148 | "description": "get(): This method is expected to be used to query for single records" 149 | }, 150 | "Service Portal: GlideRecord getRowCount()": { 151 | "prefix": "sp-record-getRowCount", 152 | "body": [ 153 | "var gr = new GlideRecord('${1:incident}');", 154 | "gr.query();", 155 | "gs.info(${2:'Records in incident table: ' + gr.getRowCount()});" 156 | ], 157 | "description": "getRowCount(): Retrieves the number of rows in the query result" 158 | }, 159 | "Service Portal: GlideRecord insert()": { 160 | "prefix": "sp-record-insert", 161 | "body": [ 162 | "var gr = new GlideRecord('${1:problem}');", 163 | "gr.initialize();", 164 | "gr.${2:short_description} = '${3:Ninja Issue}';", 165 | "gr.${4:description} = '${5:Ninja attack on CMDB}';", 166 | "gr.insert();" 167 | ], 168 | "description": "insert(): Inserts a new record using the field values that have been set for the current record" 169 | }, 170 | "Service Portal: GlideRecord setLimit()": { 171 | "prefix": "sp-record-setLimit", 172 | "body": [ 173 | "var gr = new GlideRecord('${1:incident}');", 174 | "gr.orderByDesc('${2:sys_created_on}');", 175 | "gr.setLimit(${3:10});", 176 | "gr.query();" 177 | ], 178 | "description": "setLimit(): This method is expected to be used to query for single records" 179 | }, 180 | "Service Portal: GlideRecord update()": { 181 | "prefix": "sp-record-update", 182 | "body": [ 183 | "var gr = new GlideRecord('${1:incident}');", 184 | "gr.get('${2:4c085e2e1324e700c664f8fed144b062}');", 185 | "gr.${3:category} = '${4:database}';", 186 | "gr.update();" 187 | ], 188 | "description": "update(): Updates the GlideRecord with any changes that have been made" 189 | }, 190 | "Service Portal: GlideRecord updateMultiple()": { 191 | "prefix": "sp-record-updateMultiple", 192 | "body": [ 193 | "var gr = new GlideRecord('${1:incident}')", 194 | "gr.addQuery('${2:active}', ${3:true});", 195 | "gr.query();", 196 | "gr.setValue('${4:state}', ${5:4});", 197 | "gr.updateMultiple();" 198 | ], 199 | "description": "updateMultiple(): Updates each GlideRecord in the list with any changes that have been made" 200 | }, 201 | "Service Portal: GlideSession getClientIP()": { 202 | "prefix": "sp-session-getClientIP", 203 | "body": ["var ${1:clientIP} = gs.getSession().getClientIP();"], 204 | "description": "getClientIP(): Returns the client IP address" 205 | }, 206 | "Service Portal: GlideSession getLanguage()": { 207 | "prefix": "sp-session-getLanguage", 208 | "body": ["var ${1:language} = gs.getSession().getLanguage();"], 209 | "description": "getLanguage(): Returns the session's language code" 210 | }, 211 | "Service Portal: GlideSession isLoggedIn()": { 212 | "prefix": "sp-session-isLoggedIn", 213 | "body": ["var ${1:isLoggedIn} = gs.getSession().isLoggedIn();"], 214 | "description": "isLoggedIn(): Returns true if the user is logged in" 215 | }, 216 | "Service Portal: AngularJS Module": { 217 | "prefix": "sp-ng-module", 218 | "body": [ 219 | "(function() {", 220 | "\t'use strict';", 221 | "", 222 | "\tangular.module('${1:moduleName}', []);", 223 | "})();" 224 | ], 225 | "description": "AngularJS Module: is a global place for creating, registering and retrieving AngularJS modules" 226 | }, 227 | "Service Portal: AngularJS $on": { 228 | "prefix": "sp-ng-on", 229 | "body": [ 230 | "\\$scope.\\$on('${1:eventName}', function(event, args) {", 231 | "\t$2console.log(args);", 232 | "});" 233 | ], 234 | "description": "AngularJS $on: Listens on events of a given type" 235 | }, 236 | "Service Portal: AngularJS $onInit": { 237 | "prefix": "sp-ng-onInit", 238 | "body": ["c.\\$onInit = function() {", "\t$0", "};"], 239 | "description": "AngularJS $onInit: Called on each controller after all the controllers on an element have been constructed and had their bindings initialized" 240 | }, 241 | "Service Portal: AngularJS Service": { 242 | "prefix": "sp-ng-service", 243 | "body": [ 244 | "(function() {", 245 | "\t'use strict';", 246 | "", 247 | "\tfunction ${1:serviceName}() {", 248 | "\t\tvar service = {", 249 | "\t\t\t${3:getSomething}: ${3:getSomething}", 250 | "\t\t};", 251 | "\t\treturn service;", 252 | "", 253 | "\t\tfunction ${3:getSomething}() {$0}", 254 | "\t}", 255 | "", 256 | "\tangular", 257 | "\t\t.module('${2:moduleName}')", 258 | "\t\t.service('${1:serviceName}', ${1:serviceName});", 259 | "})();" 260 | ], 261 | "description": "AngularJS Service: is a constructor function which is invoked once at runtime and wired together using dependency injection (DI)" 262 | }, 263 | "Service Portal: spModal alert": { 264 | "prefix": "sp-modal-alert", 265 | "body": [ 266 | "function OnAlertController(spModal) {", 267 | "\tvar c = this;", 268 | "\tc.${1:onAlert} = ${1:onAlert};", 269 | "", 270 | "\tfunction ${1:onAlert}() {", 271 | "\t\treturn spModal.alert('${2:How do you feel today?}').then(function(answer) {", 272 | "\t\t\tc.${3:simple} = answer;", 273 | "\t\t});", 274 | "\t}", 275 | "}" 276 | ], 277 | "description": "spModal alert: Displays an alert" 278 | }, 279 | "Service Portal: Script Include": { 280 | "prefix": "sp-script-include", 281 | "body": [ 282 | "var ${1:NewInclude} = Class.create();", 283 | "${1:NewInclude}.prototype = {", 284 | "\tinitialize: function() {},", 285 | "\t${2:myFunction}: function() {", 286 | "\t\t$0", 287 | "\t},", 288 | "\ttype: '${1:NewInclude}',", 289 | "};" 290 | ], 291 | "description": "Script includes are used to store JavaScript that runs on the server" 292 | }, 293 | "Service Portal: spModal confirm": { 294 | "prefix": "sp-modal-confirm", 295 | "body": [ 296 | "function OnConfirmController(spModal) {", 297 | "\tvar c = this;", 298 | "\tc.onConfirm = onConfirm;", 299 | "", 300 | "\tfunction onConfirm() {", 301 | "\t\tc.confirmed = 'asking';", 302 | "\t\treturn spModal.confirm('Can you confirm or deny this?').then(function(confirmed) {", 303 | "\t\t\tc.confirmed = confirmed;", 304 | "\t\t});", 305 | "\t}", 306 | "}" 307 | ], 308 | "description": "spModal confirm: Displays a confirmation message" 309 | }, 310 | "Service Portal: spModal open": { 311 | "prefix": "sp-modal-open", 312 | "body": [ 313 | "function OnWidgetController(spModal) {", 314 | "\tvar c = this;", 315 | "\tc.onWidget = onWidget;", 316 | "", 317 | "\tfunction onWidget(widgetId, widgetInput) {", 318 | "\t\treturn spModal.open({", 319 | "\t\t\ttitle: 'Displaying widget ' + widgetId,", 320 | "\t\t\twidget: widgetId,", 321 | "\t\t\twidgetInput: widgetInput || {}", 322 | "\t\t}).then(function() {", 323 | "\t\t\tconsole.log('widget dismissed');", 324 | "\t\t});", 325 | "\t}", 326 | "}" 327 | ], 328 | "description": "spModal open: Opens a modal window with an embedded widget" 329 | }, 330 | "Service Portal: spModal prompt": { 331 | "prefix": "sp-modal-prompt", 332 | "body": [ 333 | "function OnPromptController(spModal) {", 334 | "\tvar c = this;", 335 | "\tc.onPrompt = onPrompt;", 336 | "", 337 | "\tfunction onPrompt() {", 338 | "\t\treturn spModal.prompt('Your name please', c.name).then(function(name) {", 339 | "\t\t\tc.name = name;", 340 | "\t\t});", 341 | "\t}", 342 | "}" 343 | ], 344 | "description": "spModal prompt: Displays a prompt for user input" 345 | }, 346 | "Service Portal: spUtil addErrorMessage": { 347 | "prefix": "sp-util-addErrorMessage", 348 | "body": ["spUtil.addErrorMessage('${1:Sample error message}');"], 349 | "description": "addErrorMessage: Displays a notification error message" 350 | }, 351 | "Service Portal: spUtil addInfoMessage": { 352 | "prefix": "sp-util-addInfoMessage", 353 | "body": ["spUtil.addInfoMessage('${1:Sample info message}');"], 354 | "description": "addInfoMessage: Displays a notification info message" 355 | }, 356 | "Service Portal: spUtil addTrivialMessage": { 357 | "prefix": "sp-util-addTrivialMessage", 358 | "body": ["spUtil.addTrivialMessage('${1:Sample trivial message}');"], 359 | "description": "addTrivialMessage: Displays a trivial notification message" 360 | }, 361 | "Service Portal: spUtil Get Widget": { 362 | "prefix": "sp-util-get", 363 | "body": [ 364 | "function ${1:Test}Controller(spUtil) {", 365 | "\tvar c = this;", 366 | "\tc.${2:getWidget} = ${2:getWidget};", 367 | "", 368 | "\tc.\\$onInit = function() {", 369 | "\t\t${2:getWidget}();", 370 | "\t};", 371 | "", 372 | "\tfunction ${2:getWidget}() {", 373 | "\t\treturn spUtil.get('${3:widget-cool-clock}').then(function(response) {", 374 | "\t\t\tc.${4:exampleWidget} = response;", 375 | "\t\t});", 376 | "\t}", 377 | "}" 378 | ], 379 | "description": "Embedded widget: Use spUtil.get() to get a widget model in the client script" 380 | }, 381 | "Service Portal: spUtil Get Widget with Options": { 382 | "prefix": "sp-util-get-options", 383 | "body": [ 384 | "function ${1:Test}Controller(spUtil) {", 385 | "\tvar c = this;", 386 | "\tc.${2:getWidget} = ${2:getWidget};", 387 | "", 388 | "\tc.\\$onInit = function() {", 389 | "\t\t${2:getWidget}();", 390 | "\t};", 391 | "", 392 | "\tfunction ${2:getWidget}() {", 393 | "\t\treturn spUtil.get('${3:widget-cool-clock}', {${4:sys_id}: '${5:example_sys_id}'}).then(function(response) {", 394 | "\t\t\tc.${6:exampleWidget} = response;", 395 | "\t\t});", 396 | "\t}", 397 | "}" 398 | ], 399 | "description": "Embedded widget: Use spUtil.get() to get a widget model in the client script" 400 | }, 401 | "Service Portal: spUtil Record Watch": { 402 | "prefix": "sp-util-record-watch", 403 | "body": [ 404 | "spUtil.recordWatch(\\$scope, '${1:incident}', '${2:active=true}', function(name, data) {", 405 | "\t$3console.log(name);", 406 | "\t$4console.log(data);", 407 | "});" 408 | ], 409 | "description": "Record Watch: A tool that allows a widget developer to respond to table updates in real-time" 410 | } 411 | } 412 | --------------------------------------------------------------------------------