CSS Sequence (Execution Order)
ServiceNow Specific StyleSheet
Generated Bootstrap CSS
Including Portal and Theme records’ CSS at the top of this blob
Patch
Each CSS Include’s Style Sheet record’s CSS
Including Portal and Theme records’ CSS at the top of each blob
Font-Awesome
Page record’s CSS
Including Portal and Theme records’ CSS at the top of this blob
Alternating Sequence of:
Each Widget record’s CSS
Including Portal and Theme record CSS at the top of each blob
Each Widget’s Instance records’ Stylesheets
Including Portal and Theme record CSS at the top of each blob |
Angular Directives
Evaluate the given expression when the user changes the input. |
ng-change="expression"
|
Sets the checked attribute on the element |
ng-checked="boolean"
|
This directive sets the disabled attribute on the element |
ng-disabled="boolean"
|
The ngHide directive shows or hides the given HTML element based on the expression provided to the ngHide attribute. |
ng-hide|show="boolean"
|
The ngMousedown directive allows you to specify custom behavior on mousedown event. |
ng-mousedown="expression"
|
Specify custom behavior on mouseover event |
ng-mouseover="expression"
|
Specify custom behavior on blur event. A blur event fires when an element has lost focus. |
ng-blur="expression"
|
Run a loop with the data in array |
ng-repeat="([key,] value) in object|array"
|
Evaluate an if condition |
|
Client script global functions
this.server.get([Object])
|
Calls the server and sends custom input. Returns Promise. |
|
Calls the server and posts this.data to the server script. Returns Promise. |
this.server.refresh()
|
Calls the server and automatically replaces the current options and data from the server response. Returns Promise. |
A promise represents the eventual result of an asynchronous operation. For more information on promises, see https://promisesaplus.com/ or AngularJS documentation.
spAriaUtil - Client
Announce a message to a screen reader. |
spAriaUtil.sendLiveMessage('Say Hello to screen reader');
|
The spAriaUtil service is an angular service included as part of the Service Portal angular application. The spAriaUtil service is available in the client script block of Service Portal widgets.
To use the spAriaUtil please add the same to client controller
function(spAriaUtil) {
/ widget controller /
var c =this;
}
spUtil - Client
Displays a notification error message. |
spUtil.addErrorMessage("There has been an error processing your request")
|
Displays a notification info message. |
spUtil.addInfoMessage("Your order has been placed")
|
Displays a trivial notification message. Trivial messages disappear after a short period of time. |
spUtil.addTrivialMessage("Thanks for your order")
|
Use this method to embed a widget model in a widget client script. The callback function returns the full widget model. |
spUtil.get('pps-list-modal', {title: c.data.editAllocations, table: 'resource_allocation', queryString: 'GROUPBYuser^resource_plan=' + c.data.sysId, view: 'resource_portal_allocations' }).then(function(response) { var formModal = response; c.allocationListModal = response; });
|
Formats a string as an alternative to string concatenation. Use this method to build a string with variables. |
spUtil.format('An error ocurred: {error} when loading {widget}', {error: '404', widget: 'sp-widget'})
|
Calls the server and replaces the current options and data with the server response. |
spUtil.refresh($scope)
|
Updates the data object on the server within a given scope. |
|
Watches for updates to a table or filter and returns the value from the callback function. |
spUtil.recordWatch($scope, "problem", "active=true", function(response) { // Returns the data inserted or updated on the table console.log(response.data); });
|
Utility methods to perform common functions in a Service Portal widget client script.
To use the spUtil functions in the client controller, ensure that you add to client function
function(spUtil,$scope) {
/ widget controller /
var c =this;
}
Internationalize a widget
Use the ${} or gs.getMessage() syntax in widgets to tag strings for translation so you can localize your Service Portal content.
<div>
<p>${This message will be translated.}</p>
<p>However, this will nessage will NOT be translated.</p>
</div>
Now to translate the above, add the text in sys_ui_message to get the respective translation
ex:
Key: This message will be translated.
Language : 'de' / 'fr' / 'it'
Message : Add the translated text |
GlideSPScriptable - Scoped
if the user can read the specified GlideRecord.
|
$sp.canReadRecord(<gliderecord>)
|
if the user can read the specified record with table and sysID
|
$sp.canReadRecord('table', 'sys_id')
|
if the currently logged in user has permission to view the specified page
|
GlideSPScriptable.canSeePage("page_id")
|
Returns a model and view model for a sc_cat_item or sc_cat_item_guide.
|
$sp.getCatalogItem(sys_id)
|
Returns the display value of the specified field (if it exists and has a value) from either the widget's sp_instance or the sp_portal record.
|
$sp.getDisplayValue("sc_catalog")
|
Returns the portal record from the Service Portals [sp_portal] table.
|
$sp.getPortalRecord()
|
Returns an array of Service Catalog variables associated with a record.
|
$sp.getRecordVariablesArray('sc_req_itemGlide record',true(if you want variables with no values));
|
Gets a widget by id or sys_id, executes that widget's server script using the provided options, then returns the widget model.
|
$sp.getWidget('widget_id', {p1: param1, p2: param2});
|
Interact with data and perform record operations in Service Portal widgets.
You access GlideSPScriptable methods by using the global $sp object.
|
|
Global objects in widgets
Server Side Objects
input :Sent from Client script
options :Configurations mentioned in widget options when widget is loaded
data :Object or properties/value pair sent to client
Client Side Objects
options :Configurations mentioned in widget options when widget is loaded
data : Serialized data object from Server script |
The "snRecordPicker"
Creating a reference Field
<sn-record-picker field=""
table="'sys_user'"
display-field="'name'"
display-fields="'user_name'"
value-field="'sys_id'"
search-fields="'name'"
default-query="'nameLIKEAdmin'"
page-size="100" ></sn-record-picker>
|
When you try and include a reference field (such as "department") in the "display-fields" parameter, the field that you specify doesn't render other non reference fields do render correctly. This is an existing issue can be found in the KB0717097
you can pass in the filter you need to apply on reference field using default-query attribute
The "sp-date-picker"
The sp-date-picker allows to select a date and time in widgets
<sp-date-picker field="fromdate"
ng-model="c.from"
ng-model-options="{getterSetter: true}"
sn-include-time="true"
sn-disabled="false"></sp-date-picker>
|
sn-include-time property when set to true it will allow to select date and time. and when false it will allow to select only date.
FormController -(Widgets)
True if user has not interacted with the form yet. |
|
True if user has already interacted with the form. |
|
spModal - Client
Displays an alert. |
spModal.alert('Thanks for the update').then(function (answer) { c.simple = answer; });
|
Displays a confirmation message. |
spModal.confirm("Can you confirm or deny this?").then(function(confirmed) { c.confirmed = confirmed; // true or false })
|
Opens a modal window using the specified options. |
spModal.open({ title: 'Give me a name', message: 'What would you like to name it?', input: true, value: c.name }).then(function(name) { c.name = name; })
|
Displays a prompt for user input. |
spModal.prompt("Your name please", c.name).then(function(name) { c.name = name; })
|
The spModal class provides an alternative way to show alerts, prompts, and confirmation dialogs. The SPModal class is available in Service Portal client scripts.
You can use spModal.open() to display a widget in a modal dialog.
To use spModal in the client controller ensure that you add the spModal function in the client function
function(spModal) {
/ widget controller /
var c =this;
}
Embed a widget in an HTML template
Use the <widget></widget> element to embed a widget in an HTML template. Pass in the ID of the widget you are trying to embed as a parameter.
<div>
<widget id="widget-cool-clock"></widget>
</div>
If a widget has an option schema, you can define instance options in JSON format.
<widget id="widget-cool-clock" options='{"zone": "America/Los_Angeles","title": "San Diego, CA"}'>
</widget>
|
spContextManager - Client
Initializes a key and adds widget data as the value. |
spContextManager.addContext('agent-chat', { 'approval_count': 5 });
|
Returns each key and associated data object defined by any widget on the page. |
spContextManager.getContext();
|
Returns the widget data associated with a key. |
spContextManager.getContextForKey('agent-chat', true).then(function(context) { context = context || {}; context.approval_count = 5; spContextManager.updateContextForKey('agent-chat', context); });
|
Sends data to an existing key. |
spContextManager.getContextForKey('agent-chat', true).then(function(context) { context = context || {}; context.approval_count = 5; spContextManager.updateContextForKey('agent-chat', context); });
|
Make data from a Service Portal widget available to other applications and services in a Service Portal page.
to use the spContextManager, ensure to add this in the function for client controller
function ($scope, spContextManager) {
var c =this;
}
|
Created By
https://bibingokuldas.com
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by bibingokuldas