GlideSPScriptable - Scoped
-
- UpdatedFeb 1, 2024
- 12 minutes to read
- Washington DC
- API reference
Interact with data and perform record operations in Service Portal widgets.
You access GlideSPScriptable methods by using the global $sp
object.
Scoped GlideSPScriptable - canReadRecord(GlideRecord now_GR)
Returns true if the user can read the specified GlideRecord.
If the record type is kb_knowledge
, sc_cat_item
, or
sc_category
, the method checks if the user can view the item.
Name | Type | Description |
---|---|---|
now_GR | GlideRecord | The GlideRecord to check. |
Type | Description |
---|---|
Boolean | True if the record is valid and readable. |
Example
Server script
Scoped GlideSPScriptable - canReadRecord(String table, String sysId)
Returns true if the user can read the specified GlideRecord.
If the record type is kb_knowledge
, sc_cat_item
, or
sc_category
, the method checks if the user can view the item.
Name | Type | Description |
---|---|---|
table | String | Name of the table to query. |
sysId | String | Sys_id of the record to query. |
Type | Description |
---|---|
Boolean | True if the record is valid and readable. |
Scoped GlideSPScriptable - canSeePage(String pageID)
Returns true if the currently logged in user has permission to view the specified page.
The system determines permission using roles and user criteria. For more information, see Configure page security by role and User criteria for Service Portal.
Name | Type | Description |
---|---|---|
pageID | String | Page ID from the Pages [sp_page] table. |
Type | Description |
---|---|
Boolean | Flag that indicates whether the currently logged in user has permissions to
view the specified page. Values include:
|
Example
This example adds a condition to the Knowledge menu item in the SP Header Menu to only show the menu item to users who have permission to view the kb_view2 page.
Scoped GlideSPScriptable - getCatalogItem(String sysId)
Returns a model and view model for a sc_cat_item
or
sc_cat_item_guide
.
This method is deprecated. Use the getCatalogItem(String sysId, Boolean isOrdering) method instead. This method calls the getCatalogItem(String sysId, Boolean isOrdering) method with the isOrdering parameter set to false, which means that write roles security checking is done.
This method is a quick way to get the data necessary to render and order a catalog item
using <sp-model />
. If you just need to get a catalog item to show its
picture or name, use GlideRecord to query the sc_cat_item
table.
Name | Type | Description |
---|---|---|
sysId | String | The sys_id of the catalog item (sc_cat_item ) or order guide
(sc_cat_item_guide ). |
Type | Description |
---|---|
Object | An object containing the catalog item variable model, view, sections, pricing, and client scripts. |
Example
Scoped GlideSPScriptable - getCatalogItem(String sysId, Boolean isOrdering)
Returns a model and view model for a sc_cat_item
or
sc_cat_item_guide
.
Name | Type | Description |
---|---|---|
sysId | String | The sys_id of the catalog item (sc_cat_item ) or order guide
(sc_cat_item_guide ). |
isOrdering | Boolean | When true, uses create roles security check. When false, uses write roles
security check. When users are ordering an item or have it in their cart, check using the create roles. If users are not ordering, for example, somebody is looking at a requested item to see the variables associated with that item, then check using the write roles. |
Type | Description |
---|---|
Object | An object containing the catalog item variable model, view, sections, pricing, and client scripts. |
Scoped GlideSPScriptable - getDisplayValue(String fieldName)
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.
Name | Type | Description |
---|---|---|
fieldName | String | Name of the field |
Type | Description |
---|---|
String | The display value from either the sp_instance or
sp_portal record. |
Example
Scoped GlideSPScriptable - getField(GlideRecord now_GR, String fieldName)
Returns information about the specified field in the specified GlideRecord.
Name | Type | Description |
---|---|---|
now_GR | GlideRecord | The GlideRecord to check |
fieldName | String | The field to find information for |
Type | Description |
---|---|
Object | An object containing the field's label, value, displayValue, and type. Returns null if the GlideRecord of field name are not valid, or if the field is not readable. |
Scoped GlideSPScriptable - getFields(GlideRecord now_GR, String fieldNames)
Checks the specified list of field names, and returns an array of valid field names.
Name | Type | Description |
---|---|---|
now_GR | GlideRecord | The GlideRecord to check |
field Names | String | A comma separated list of field names. |
Type | Description |
---|---|
Array | An array of valid fields. |
Scoped GlideSPScriptable - getFieldsObject(GlideRecord now_GR, String fieldNames)
Checks the specified list of field names and returns an object of valid field names.
Name | Type | Description |
---|---|---|
now_GR | GlideRecord | The GlideRecord to check |
field Names | String | A comma separated list of field names. |
Type | Description |
---|---|
Object | An object containing valid field names. |
Scoped GlideSPScriptable - getForm(String tableName, String sysId)
Return the form.
Name | Type | Description |
---|---|---|
tableName | String | The name of the table |
sysId | String | The form's sys_id |
Type | Description |
---|---|
Object | The form |
Scoped GlideSPScriptable - getKBCategoryArticles(String sys_id, Number limit)
Returns KB articles in the specified category and its subcategories.
To avoid performance issues, do not use this method to return articles in large categories or articles with inline images. Instead, use getKBArticleSummaries().
Name | Type | Description |
---|---|---|
sys_id | String | Sys_id of the KB article category. |
limit | Number | Maximum number of KB articles returned. |
Type | Description |
---|---|
Array | The articles within the category and its subcategories with:
|
Example
Scoped GlideSPScriptable - getKBCategoryArticleSummaries(String sys_id, Number limit, Number maxChars)
Returns Knowledge Base article summaries in the specified category and its subcategories.
Name | Type | Description |
---|---|---|
sys_id | String | Sys_id of the KB article category. |
limit | Number | Maximum number of KB articles returned. |
maxChars | Number | Maximum number of characters to return from the article text. For full article
text, set the value to -1 . |
Type | Description |
---|---|
Array | The articles within the category and its subcategories with:
|
Example
Scoped GlideSPScriptable - getKBCount(String sys_id)
Returns the number of articles in the defined Knowledge Base.
Name | Type | Description |
---|---|---|
sys_id | String | Sys_id of a Knowledge Base record. |
Type | Description |
---|---|
Number | Number of knowledge articles in the defined Knowledge Base with:
|
Example
Scoped GlideSPScriptable - getListColumns(String tableName, String view)
Returns a list of the specified table's columns in the specified view.
Name | Type | Description |
---|---|---|
tableName | String | Name of the table |
view | String | The view by which to filter the columns |
Type | Description |
---|---|
Object | An object containing the column names. |
Scoped GlideSPScriptable - getMenuItems(String sysId)
Returns an array of menu items for the specified instance.
Name | Type | Description |
---|---|---|
sysId | String | sysId of the instance |
Type | Description |
---|---|
Array | Menu items for the specified instance |
Scoped GlideSPScriptable - getMenuHREF(GlideRecord page)
Returns the (?id=) portion of the URL based on the sp_menu type.
Name | Type | Description |
---|---|---|
page | GlideRecord | The page |
Type | Description |
---|---|
String | The href portion of the URL. |
Scoped GlideSPScriptable - getParameter(String name)
Returns the value of the specified parameter.
Name | Type | Description |
---|---|---|
name | String | The name of the key from the query string or post body. |
Type | Description |
---|---|
Object | Returns the specified parameter as an object. Returns null if there is no request, JSON request, or widget. |
Scoped GlideSPScriptable - getPortalRecord()
Returns the portal record from the Service Portals [sp_portal] table.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideRecord | The portal record for the current portal from the Service Portals [sp_portal] table. |
Example
Scoped GlideSPScriptable - getRecord(String table, String sys_id)
If parameters are provided, returns the GlideRecord identified by the provided table and Sys ID. If no parameters are provided, returns the record identified by the current URL.
Name | Type | Description |
---|---|---|
table | String | Optional. The table of the record to return. If no parameters are included, returns the table and Sys ID identified by the current URL. |
sys_id | String | Optional. The Sys ID of the record to return. If no parameters are included, returns the record identified by the current URL. |
Type | Description |
---|---|
GlideRecord | If parameters are provided, returns the record identified by the provided table
and Sys ID. If no parameters are provided, returns the record identified by the current URL. Returns null if the widget is embedded by another widget, or if the record for the provided parameters is not found. |
Example
Scoped GlideSPScriptable - getRecordDisplayValues(Object data, GlideRecord from, String names)
Copies display values for the specified fields into the data parameter.
Name | Type | Description |
---|---|---|
data | Object | The display values for the specified fields are copied to this object. |
from | GlideRecord | The GlideRecord to process. |
names | String | A comma-separated list of field names. |
Type | Description |
---|---|
void |
Scoped GlideSPScriptable - getRecordElements(Object data, GlideRecord from, String names)
For the specified fields, copies the element's name, display value, and value into the data parameter.
Name | Type | Description |
---|---|---|
data | Object | The element's name, display value, and value for the specified fields are copied to this object. |
from | GlideRecord | The GlideRecord to process. |
names | String | A comma-separated list of field names. |
Type | Description |
---|---|
void |
Scoped GlideSPScriptable - getRecordValues(Object data, GlideRecord from, String names)
Copies values for the specified field names from the GlideRecord into the data parameter.
Name | Type | Description |
---|---|---|
data | Object | The value for the specified fields are copied to this object. |
from | GlideRecord | The GlideRecord to process. |
names | String | A comma-separated list of field names. |
Type | Description |
---|---|
void |
Scoped GlideSPScriptable - getRecordVariables(GlideRecord now_GR, Boolean includeNilResponses)
Returns Service Catalog variables associated with a record in String format.
Name | Type | Description |
---|---|---|
now_GR | GlideRecord | The record to retrieve Service Catalog variables for. Must be a record with Service Catalog variables defined, such as a requested item [sc_req_item] record or an incident submitted through a record producer. |
includeNilResponses | Boolean | Optional. If true, the API includes variables with no user-defined value. |
Type | Description |
---|---|
String | Service Catalog variables associated with the record. |
Example
Output:
Scoped GlideSPScriptable - getRecordVariablesArray(GlideRecord now_GR, Boolean includeNilResponses)
Returns an array of Service Catalog variables associated with a record.
Name | Type | Description |
---|---|---|
now_GR | GlideRecord | The record to retrieve Service Catalog variables for. Must be a record with Service Catalog variables defined, such as a requested item [sc_req_item] record or an incident submitted through a record producer. |
includeNilResponses | Boolean | Optional. If true, the API includes variables with no user-defined value. |
Type | Description |
---|---|
Object | Array of Service Catalog variables associated with the record. |
Example
Output:
Scoped GlideSPScriptable - getStream(String table, String sysId)
Gets the activity stream for the specified record. This method works on tables that extend the task table.
Name | Type | Description |
---|---|---|
table | String | The table name |
sysID | String | The sys_id of the record |
Type | Description |
---|---|
Object | If a table extending the task table is specified, contains the display_value,
sys_id, short_description,number, entries, user_sys_id, user_full_name, user_login,
label, table, and journal_fields properties; otherwise contains the table and sys_id
properties. Note: The user_login property contains the User ID of the current user.
The user_sys_id and iser_full_name properties reference the creator of the queried
record. |
Scoped GlideSPScriptable - getUserInitials()
Returns the user's initials.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | The user's initials |
Scoped GlideSPScriptable - getValue(String name)
Returns the named value of the JSON request, instance, or portal.
Name | Type | Description |
---|---|---|
name | String | Name of the JSON request, instance, or portal. |
Type | Description |
---|---|
Object | Value of the specified parameter. Null if the specified entity does not exist or has no such parameter. |
Example
Scoped GlideSPScriptable - getValues(Object data, String names)
Copies values from the request or instance to the data parameter.
Name | Type | Description |
---|---|---|
data | Object | Receives the parameter values. |
names | String | Comma-separated string of field names. |
Type | Description |
---|---|
void |
Scoped GlideSPScriptable - getVariablesArray(Boolean includeNilResponses)
Returns an array of Service Catalog variables associated with the record in the URL.
For example, if the URL includes the parameters
id=form&table=sc_req_item&sys_id=832e9620db4f330083766b984b9619cf
,
the API returns the variables associated with the given record in the Requested item
[sc_req_item] table. Must be a record with Service Catalog variables
defined, such as a requested item [sc_req_item] record or an incident submitted through a
record producer.
Name | Type | Description |
---|---|---|
includeNilResponses | Boolean | Optional. If true, the API includes variables with no user-defined value. |
Type | Description |
---|---|
Object | Array of variables associated with the table. |
Example
Output:
Scoped GlideSPScriptable - getWidget(String sysID, Object options)
Gets a widget by id or sys_id, executes that widget's server script using the provided options, then returns the widget model.
Name | Type | Description |
---|---|---|
sysID | String | The widget sys_id or widget_id |
options | Object | An object to pass to the widget's server script. Refer to this object as
options in your server script.Note: Any options passed into this
function will only be available in the embedded widget's server script on the
first execution of that script. Any subsequent calls into
the server script from the embedded widget will not contain the object properties
passed in. |
Type | Description |
---|---|
Object | A widget model to be used with sp-widget. |
Example
Scoped GlideSPScriptable - isRTLEnabled()
Checks whether the associated portal is enabled for right-to-left language (RTL) and whether the current user's language is directionally RTL.
Use this method to determine if there’s a need for a RTL-specific CSS in the portal UI.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | Flag that indicates whether the RTL flag is enabled and the current user's session language is directionally RTL. Possible values:
Data type: Boolean |
Example
The following code example shows how to use this method to determine the type of icon to display on the portal page.
Scoped GlideSPScriptable - isUserCriteriaEnabled()
Returns true if user criteria is enabled.
This method returns true if the Service Portal User Criteria Support plugin (com.glide.service-portal.user-criteria) is active and the Enable use of User Criteria records instead of Roles fields for Service Portal entitlements (glide.service_portal.user_criteria_enabled) system property is set to true.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if user criteria is enabled. |
Scoped GlideSPScriptable - log(Object message)
Logs output to the Service Portal Log Entries [sp_log] table. The logged in user must have the sp_admin or admin role.
Name | Type | Description |
---|---|---|
message | Object | JavaScript object or string representing the message to send as output on a Service Portal page. |
Type | Description |
---|---|
None |
Example
The following example shows how to log a predefined error if it occurs.
Scoped GlideSPScriptable - mapUrlToSPUrl(String url)
Transforms a URL requesting a list or form in the platform UI into the URL of the
corresponding id=list
or id=form
Service Portal
page.
id=list
and id=form
page targets are not
customizable.Name | Type | Description |
---|---|---|
url | String | Platform UI URL |
Type | Description |
---|---|
String | Transformed Service Portal URL. If the passed-in URL does not request a list or a form in the platform UI, a null value is returned. |
Example
List example
Returns
Example
Form example
Returns
Scoped GlideSPScriptable - userCanSeeSearchSourceByCriteria(String searchSourceID)
Returns true if the current user can see a search source specified by the searchSourceID.
Name | Type | Description |
---|---|---|
searchSourceID | String | Sys_id of the search source record. |
Type | Description |
---|---|
Boolean | True if current user has read access to the search source. |
On this page
- Scoped GlideSPScriptable - canReadRecord(GlideRecord now_GR)
- Scoped GlideSPScriptable - canReadRecord(String table, String sysId)
- Scoped GlideSPScriptable - canSeePage(String pageID)
- Scoped GlideSPScriptable - getCatalogItem(String sysId)
- Scoped GlideSPScriptable - getCatalogItem(String sysId, Boolean isOrdering)
- Scoped GlideSPScriptable - getDisplayValue(String fieldName)
- Scoped GlideSPScriptable - getField(GlideRecord now_GR, String fieldName)
- Scoped GlideSPScriptable - getFields(GlideRecord now_GR, String fieldNames)
- Scoped GlideSPScriptable - getFieldsObject(GlideRecord now_GR, String fieldNames)
- Scoped GlideSPScriptable - getForm(String tableName, String sysId)
- Scoped GlideSPScriptable - getKBCategoryArticles(String sys_id, Number limit)
- Scoped GlideSPScriptable - getKBCategoryArticleSummaries(String sys_id, Number limit,
Number maxChars)
- Scoped GlideSPScriptable - getKBCount(String sys_id)
- Scoped GlideSPScriptable - getListColumns(String tableName, String view)
- Scoped GlideSPScriptable - getMenuItems(String sysId)
- Scoped GlideSPScriptable - getMenuHREF(GlideRecord page)
- Scoped GlideSPScriptable - getParameter(String name)
- Scoped GlideSPScriptable - getPortalRecord()
- Scoped GlideSPScriptable - getRecord(String table, String sys_id)
- Scoped GlideSPScriptable - getRecordDisplayValues(Object data, GlideRecord from, String
names)
- Scoped GlideSPScriptable - getRecordElements(Object data, GlideRecord from, String
names)
- Scoped GlideSPScriptable - getRecordValues(Object data, GlideRecord from, String
names)
- Scoped GlideSPScriptable - getRecordVariables(GlideRecord now_GR, Boolean
includeNilResponses)
- Scoped GlideSPScriptable - getRecordVariablesArray(GlideRecord now_GR, Boolean
includeNilResponses)
- Scoped GlideSPScriptable - getStream(String table, String sysId)
- Scoped GlideSPScriptable - getUserInitials()
- Scoped GlideSPScriptable - getValue(String name)
- Scoped GlideSPScriptable - getValues(Object data, String names)
- Scoped GlideSPScriptable - getVariablesArray(Boolean includeNilResponses)
- Scoped GlideSPScriptable - getWidget(String sysID, Object options)
- Scoped GlideSPScriptable - isRTLEnabled()
- Scoped GlideSPScriptable - isUserCriteriaEnabled()
- Scoped GlideSPScriptable - log(Object message)
- Scoped GlideSPScriptable - mapUrlToSPUrl(String url)
- Scoped GlideSPScriptable - userCanSeeSearchSourceByCriteria(String searchSourceID)