You are on page 1of 1

Service Portal Cheat Sheet

spUtil API Reference brought to you by NEWROCKET.com

spUtil enables you to perform common functions in a Service Portal widget client script. Method (Parameters) Description  
How to Use: Pass in spUtil as a parameter in your Client Script function. getURL Utilized client side in conjunction with $http to submit catalog
function (spUtil) { (String type, items.
spUtil.addInfoMessage(“Hello World“); Object type) Return: (String)
} getWidgetURL Returns SNOW API REST endpoint URL used to
(N/A) communicate with SNOW instance.
Method (Parameters) Description Return: (String)
addErrorMessage Displays a notification error message. isMobile Scans current navigator user agent to determine if current
(String message) Return: (Void) (N/A) user is on a mobile device.
addInfoMessage Displays a notification info message. Return: (Boolean)
(String message) Return: (Void) parseAttributes Given a string of URL attributes, returns an object containing
addTrivialMessage Displays a trivial notification message. Trivial messages (String attributes) same detail.
(String message) disappear after a short period of time. Return: (String)
Return: (Void) recordWatch Watches for updates to a table or filter and returns the value
clearMessages Clears any info or error message. Broadcasts (Object $scope, from the callback function. Allows a widget developer to
(N/A) “$$uiNotification.dismiss” event to rootscope. String table, String filter, respond to table updates in real-time. This method returns
createUid Uses a provided string to generate a UID. Function callback) the value of the callback function. When the record watcher
(String str) Return: (String) triggers, it will call the callback function provided in this
format Formats a string as an alternative to string concatenation. method (or simply trigger a $scope.server.update()).
(String template, Use this method to build a string with variables. This method Return: (Void)
Object data) returns a formatted string. refresh Calls the server and replaces the current options and data
Return: (String) (Object $scope) with the server response. Calling spUtil.refresh() is similar
get Returns a widget model by ID or sys_id. Use this method to to calling server.refresh(). However, when you call spUtil.
(String widgetId, embed a widget model in a widget client script. The callback refresh(), you can define the $scope object. This method
Object data) function returns the full widget model. Checks the specified returns the upated options and data objects.
list of field names, and returns an array of valid field names. Return: (Object)
This method returns the model of the embedded widget. scrollTo Scrolls view to the selector provided in the time provided.
Return: (Object) (String elementID, The elementID refers to the actual ID of the element within
getAccelerator If Mac user agent, returns back “Cmd + char”, Integer scrollDelayInMS) the widget. After a given delay, the selected element will
(String char) else “Ctrl + char”. scroll into view.
Return: (String) Return: (Void)
getHeaders Returns an object containing header details, includes an setBreadCrumb Given a list of breadcrumb labels/values, update
(N/A) attribute which references the portal ID. (Scope $scope, breadcrumbs on the form.
Return: (Object) Array list) Return: (Void)
getHost Returns base instance URL (including https:// prefix). setPreference Updates the user preference value.
(N/A) Return: (String) (String preferenceName, Return: (Void)
getMomentTimeZone This will attempt to map a three letter timezone symbol into String value)
(N/A) it’s fully qualified name. setSearchPage Should emit an update.searchpage event with the search
Return: (String) (String searchPage) page provided.
getPageUri Returns page URI. Return: (Void)
(N/A) Return: (String) update Updates the data object on the server within a given scope.
getPreference Looks up user preference value and then passes value (String preferenceName, This method is similar to server.update(), but includes a
(String preferenceName, into callback function. String value) $scope parameter that defines the scope to pass over.
Function callback) Return: (Void) This method returns the updated data object.
Return: (Object)

Visit serviceportal.io for our latest tutorials and insights, or stop by newrocket.com to see our products and services.

You might also like