---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideSPScriptable - Scoped

# GlideSPScriptable - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 15 minutes to read

The GlideSPScriptable API provides methods to interact with data and perform record operations in Service Portal widgets.

You access GlideSPScriptable methods by using the global `$sp` object.

## GlideSPScriptable - canReadRecord(GlideRecord now_GR) {#ariaid-title2}

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.
{#r_GSPS-canReadRecord_GR__table_g5p_w4l_3w__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | The GlideRecord to check. |
[Table 1. Parameters]

{#r_GSPS-canReadRecord_GR__table_g5p_w4l_3w} {#r_GSPS-canReadRecord_GR__table_h5p_w4l_3w__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the record is valid and readable. |
[Table 2. Returns]

{#r_GSPS-canReadRecord_GR__table_h5p_w4l_3w}  
Server script

    //Server script
    data.items = [];
    data.userName = gs.getUserDisplayName();
    var now_GR = new GlideRecord("sc_cat_item");
    now_GR.query();
    while(now_GR.next() && data.items.length < 10) {
        if ($sp.canReadRecord(now_GR)) {
        data.items.push(now_GR.getDisplayValue("name"));
        }
    }

    //HTML template
    <div class="panel panel-default">
        <div class="panel-heading">Hi, {{c.data.userName}}!</div>
        <div class="panel-body">
            Here are some things you can order:
            <ul><li ng-repeat="item in c.data.items">{{item}}</li></ul>
        </div>
    </div>

## GlideSPScriptable - canReadRecord(String table, String sysId) {#ariaid-title3}

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.
{#r_GSPS-canReadRecord_S_S__table_bvn_5pl_3w__entry__3}

| Name | Type | Description |
|-|-|-|
| table | String | Name of the table to query. |
| sysId | String | Sys_id of the record to query. |
[Table 3. Parameters]

{#r_GSPS-canReadRecord_S_S__table_bvn_5pl_3w} {#r_GSPS-canReadRecord_S_S__table_cvn_5pl_3w__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the record is valid and readable. |
[Table 4. Returns]

{#r_GSPS-canReadRecord_S_S__table_cvn_5pl_3w}

## GlideSPScriptable - canSeePage(String pageID) {#ariaid-title4}

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](https://www.servicenow.com/docs/access?context=configure-page-security&version=xanadu&pubname=xanadu-platform-user-interface&ft:locale=en-US)
and [User criteria for Service
Portal](https://www.servicenow.com/docs/access?context=user-criteria&version=xanadu&pubname=xanadu-platform-user-interface&ft:locale=en-US).
{#GSPS-canSeePage_S__table_szf_mxq_s3b__entry__3}

| Name | Type | Description |
|-|-|-|
| pageID | String | Page ID from the Pages \[sp_page\] table. |
[Table 5. Parameters]

{#GSPS-canSeePage_S__table_szf_mxq_s3b} {#GSPS-canSeePage_S__table_tzf_mxq_s3b__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the currently logged in user has permissions to view the specified page. Values include: * true: The user can view the page. * false: Either the user cannot view the page, the given pageID is not valid, or the user is not logged in. {#GSPS-canSeePage_S__ul_r2f_dyq_s3b} |
[Table 6. Returns]

{#GSPS-canSeePage_S__table_tzf_mxq_s3b}  
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.

    GlideSPScriptable.canSeePage("kb_view2")

## GlideSPScriptable - getCatalogItem(String sysId) {#ariaid-title5}

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.
{#r_GSPS-getCatalogItem_S__table_zdz_jrl_3w__entry__3}

| Name | Type | Description |
|-|-|-|
| sysId | String | The sys_id of the catalog item (`sc_cat_item`) or order guide (`sc_cat_item_guide`). |
[Table 7. Parameters]

{#r_GSPS-getCatalogItem_S__table_zdz_jrl_3w} {#r_GSPS-getCatalogItem_S__table_a2z_jrl_3w__entry__2}

| Type | Description |
|-|-|
| Object | An object containing the catalog item variable model, view, sections, pricing, and client scripts. |
[Table 8. Returns]

{#r_GSPS-getCatalogItem_S__table_a2z_jrl_3w}  

    // Server script
    (function() {
        var sys_id = $sp.getParameter("sys_id")
        data.catItem = $sp.getCatalogItem(sys_id);
    })();

    // Client script
    function($http, spUtil) {
        var c = this;
        var submitting = false;
        c.getIt = function() {
            if (submitting) return;
            $http.post(spUtil.getURL('sc_cat_item'), c.data.catItem).success(function(response) {
                if (response.answer) {
                    c.req = response.answer;
                    c.req.page = c.req.table == 'sc_request' ? 'sc_request' : 'ticket';
                }
            });
        }
    }

    //SCSS
    .img-bg {
        padding: 5px;
        background-color: $brand-primary;
    }

    .img-responsive {
        margin: 0 auto;
    }

    .cat-icon {
        display: block;
        margin: -40px auto 0;
    }

    // HTML template
    <div class="col-sm-4">
      <div class="panel panel-default">
        <div class="img-bg">
          <img ng-src="{{::data.catItem.picture}}" class="img-responsive" />
        </div>
        <span class="cat-icon fa fa-stack fa-lg fa-3x hidden-xs">
          <i class="fa fa-circle fa-stack-2x text-success"></i>
          <i class="fa fa-desktop fa-stack-1x fa-inverse"></i>
        </span>
        <div class="panel-body">
          <p class="lead text-center">{{::data.catItem.name}}</p>
          <ul class="list-unstyled">
            <li class="text-center" ng-if="::data.catItem.price">${Price}: {{::data.catItem.price}}</li>
          </ul>
          <sp-model form-model="::data.catItem" mandatory="mandatory"></sp-model>
          <p ng-if="c.req" class="text-center text-success">
            ${Request created!} <a href="?id={{c.req.page}}&table={{c.req.table}}&sys_id={{c.req.sys_id}}">{{c.req.number}}</a>
          </p>
          <button ng-if="!c.req" class="btn btn-default btn-block" ng-click="c.getIt()">${Get it}</button>
        </div>
      </div>
    </div>

## GlideSPScriptable - getCatalogItem(String sysId, Boolean isOrdering) {#ariaid-title6}

Returns a model and view model for a `sc_cat_item` or
`sc_cat_item_guide`.
{#r_GSPS-getCatalogItem_S_B__table_xj4_rw2_3z__entry__3}

| 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. |
[Table 9. Parameters]

{#r_GSPS-getCatalogItem_S_B__table_xj4_rw2_3z} {#r_GSPS-getCatalogItem_S_B__table_yj4_rw2_3z__entry__2}

| Type | Description |
|-|-|
| Object | An object containing the catalog item variable model, view, sections, pricing, and client scripts. |
[Table 10. Returns]

{#r_GSPS-getCatalogItem_S_B__table_yj4_rw2_3z}

## GlideSPScriptable - getDisplayValue(String fieldName) {#ariaid-title7}

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.
{#r_GSPS-getDisplayValue_S__table_xz2_btl_3w__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | Name of the field |
[Table 11. Parameters]

{#r_GSPS-getDisplayValue_S__table_xz2_btl_3w} {#r_GSPS-getDisplayValue_S__table_yz2_btl_3w__entry__2}

| Type | Description |
|-|-|
| String | The display value from either the `sp_instance` or `sp_portal` record. |
[Table 12. Returns]

{#r_GSPS-getDisplayValue_S__table_yz2_btl_3w}  

    //Server script
    (function() {
        data.title = $sp.getDisplayValue("title");
        data.catalog = $sp.getDisplayValue("sc_catalog");
    })();

    //HTML template
    <div>
        <h1>sp_instance.title: {{::data.title}}</h1>
        <h1>sp_portal.sc_catalog: {{::data.catalog}}</h1>
    </div>

## GlideSPScriptable - getField(GlideRecord now_GR, String fieldName) {#ariaid-title8}

Returns information about the specified field in the specified GlideRecord.
{#r_GSPS-getField_GR_S__table_t3k_ggg_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | The GlideRecord to check |
| fieldName | String | The field to find information for |
[Table 13. Parameters]

{#r_GSPS-getField_GR_S__table_t3k_ggg_jw} {#r_GSPS-getField_GR_S__table_u3k_ggg_jw__entry__2}

| 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. |
[Table 14. Returns]

{#r_GSPS-getField_GR_S__table_u3k_ggg_jw}

## GlideSPScriptable - getFields(GlideRecord now_GR, String fieldNames) {#ariaid-title9}

Checks the specified list of field names, and returns an array of valid field
names.
{#r_GSPS-getFields_GR_S__table_npj_ctg_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | The GlideRecord to check |
| field Names | String | A comma separated list of field names. |
[Table 15. Parameters]

{#r_GSPS-getFields_GR_S__table_npj_ctg_jw} {#r_GSPS-getFields_GR_S__table_opj_ctg_jw__entry__2}

| Type | Description |
|-|-|
| Array | An array of valid fields. |
[Table 16. Returns]

{#r_GSPS-getFields_GR_S__table_opj_ctg_jw}

## GlideSPScriptable - getFieldsObject(GlideRecord now_GR, String fieldNames) {#ariaid-title10}

Checks the specified list of field names and returns an object of valid field
names.
{#r_GSPS-getFieldsObject_GR_S__table_bkz_5tg_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | The GlideRecord to check |
| field Names | String | A comma separated list of field names. |
[Table 17. Parameters]

{#r_GSPS-getFieldsObject_GR_S__table_bkz_5tg_jw} {#r_GSPS-getFieldsObject_GR_S__table_ckz_5tg_jw__entry__2}

| Type | Description |
|-|-|
| Object | An object containing valid field names. |
[Table 18. Returns]

{#r_GSPS-getFieldsObject_GR_S__table_ckz_5tg_jw}

## GlideSPScriptable - getForm(String tableName, String sysId) {#ariaid-title11}

Return the form.
{#r_GSPS-getForm_S_S__table_m2z_cvg_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | The name of the table |
| sysId | String | The form's sys_id |
[Table 19. Parameters]

{#r_GSPS-getForm_S_S__table_m2z_cvg_jw} {#r_GSPS-getForm_S_S__table_n2z_cvg_jw__entry__2}

| Type | Description |
|-|-|
| Object | The form |
[Table 20. Returns]

{#r_GSPS-getForm_S_S__table_n2z_cvg_jw}

## GlideSPScriptable - getKBCategoryArticles(String sys_id, Number limit) {#ariaid-title12}

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().
{#GSPS-getKBCategoryArticles_S_N__table_k14_331_xbb__entry__3}

| Name | Type | Description |
|-|-|-|
| sys_id | String | Sys_id of the KB article category. |
| limit | Number | Maximum number of KB articles returned. |
[Table 21. Parameters]

{#GSPS-getKBCategoryArticles_S_N__table_k14_331_xbb} {#GSPS-getKBCategoryArticles_S_N__table_l14_331_xbb__entry__2}

| Type | Description |
|-|-|
| Array | The articles within the category and its subcategories with: * A workflow_state of published. * A valid_to date greater than or equal to the current date. {#GSPS-getKBCategoryArticles_S_N__ul_qxn_1hh_xbb} |
[Table 22. Returns]

{#GSPS-getKBCategoryArticles_S_N__table_l14_331_xbb}  

    //Server script 
    (function() {
        data.kbs = $sp.getKBCategoryArticles("0ac1bf8bff0221009b20ffffffffffec", 5);
    })();

    //HTML template
    <div>
    articles: {{::data.kbs}}
    </div>

## GlideSPScriptable - getKBCategoryArticleSummaries(String sys_id, Number limit, Number maxChars) {#ariaid-title13}

Returns Knowledge Base article summaries in the specified category and its
subcategories.
{#GSPS-getKBCategoryArticleSummaries_S_N_N__table_j44_gjh_xbb__entry__3}

| 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`. |
[Table 23. Parameters]

{#GSPS-getKBCategoryArticleSummaries_S_N_N__table_j44_gjh_xbb} {#GSPS-getKBCategoryArticleSummaries_S_N_N__table_k44_gjh_xbb__entry__2}

| Type | Description |
|-|-|
| Array | The articles within the category and its subcategories with: * A workflow_state of published. * A valid_to date greater than or equal to the current date. {#GSPS-getKBCategoryArticleSummaries_S_N_N__ul_qxn_1hh_xbb} |
[Table 24. Returns]

{#GSPS-getKBCategoryArticleSummaries_S_N_N__table_k44_gjh_xbb}  

    //Server script 
    (function() {
        data.summary = $sp.getKBCategoryArticleSummaries("0ac1bf8bff0221009b20ffffffffffec", 5, 200);
    })();

    //HTML template
    <div>
    articles: {{::data.summary}}
    </div>

## GlideSPScriptable - getKBCount(String sys_id) {#ariaid-title14}

Returns the number of articles in the defined Knowledge Base.
{#GSPS-getKBCount_S__table_k1v_js1_xbb__entry__3}

| Name | Type | Description |
|-|-|-|
| sys_id | String | Sys_id of a Knowledge Base record. |
[Table 25. Parameters]

{#GSPS-getKBCount_S__table_k1v_js1_xbb} {#GSPS-getKBCount_S__table_l1v_js1_xbb__entry__2}

| Type | Description |
|-|-|
| Number | Number of knowledge articles in the defined Knowledge Base with: * A workflow_state of published. * A valid_to date greater than or equal to the current date. {#GSPS-getKBCount_S__ul_kfs_bhh_xbb} |
[Table 26. Returns]

{#GSPS-getKBCount_S__table_l1v_js1_xbb}  

    //Server script 
    (function() {
        data.count = $sp.getKBCount("a7e8a78bff0221009b20ffffffffff17");
    })();

    //HTML template
    <div>
    articles: {{::data.count}}
    </div>

## GlideSPScriptable - getListColumns(String tableName, String view) {#ariaid-title15}

Returns a list of the specified table's columns in the specified view.
{#r_GSPS-getListColumns_S_S__table_tzc_dwg_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Name of the table |
| view | String | The view by which to filter the columns |
[Table 27. Parameters]

{#r_GSPS-getListColumns_S_S__table_tzc_dwg_jw} {#r_GSPS-getListColumns_S_S__table_uzc_dwg_jw__entry__2}

| Type | Description |
|-|-|
| Object | An object containing the column names. |
[Table 28. Returns]

{#r_GSPS-getListColumns_S_S__table_uzc_dwg_jw}

## GlideSPScriptable - getMenuItems(String sysId) {#ariaid-title16}

Returns an array of menu items for the specified instance.
{#r_GSPS-getMenuItems_S__table_nnj_tch_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| sysId | String | sysId of the instance |
[Table 29. Parameters]

{#r_GSPS-getMenuItems_S__table_nnj_tch_jw} {#r_GSPS-getMenuItems_S__table_onj_tch_jw__entry__2}

| Type | Description |
|-|-|
| Array | Menu items for the specified instance |
[Table 30. Returns]

{#r_GSPS-getMenuItems_S__table_onj_tch_jw}

## GlideSPScriptable - getMenuHREF(GlideRecord page) {#ariaid-title17}

Returns the (?id=) portion of the URL based on the sp_menu type.
{#r_GSPS-getMenuHREF_GR__table_w4w_gdh_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| page | GlideRecord | The page |
[Table 31. Parameters]

{#r_GSPS-getMenuHREF_GR__table_w4w_gdh_jw} {#r_GSPS-getMenuHREF_GR__table_x4w_gdh_jw__entry__2}

| Type | Description |
|-|-|
| String | The href portion of the URL. |
[Table 32. Returns]

{#r_GSPS-getMenuHREF_GR__table_x4w_gdh_jw}

## GlideSPScriptable - getParameter(String name) {#ariaid-title18}

Returns the value of the specified parameter.
{#r_GSPS-getParameter_S__table_zjj_22h_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the key from the query string or post body. |
[Table 33. Parameters]

{#r_GSPS-getParameter_S__table_zjj_22h_jw} {#r_GSPS-getParameter_S__table_akj_22h_jw__entry__2}

| Type | Description |
|-|-|
| Object | Returns the specified parameter as an object. Returns null if there is no request, JSON request, or widget. |
[Table 34. Returns]

{#r_GSPS-getParameter_S__table_akj_22h_jw}

## GlideSPScriptable - getPortalRecord() {#ariaid-title19}

Returns the portal record from the Service Portals \[sp_portal\] table.
{#r_GSPS-getPortalRecord__table_dwm_52h_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 35. Parameters]

{#r_GSPS-getPortalRecord__table_dwm_52h_jw} {#r_GSPS-getPortalRecord__table_ewm_52h_jw__entry__2}

| Type | Description |
|-|-|
| GlideRecord | The portal record for the current portal from the Service Portals \[sp_portal\] table. |
[Table 36. Returns]

{#r_GSPS-getPortalRecord__table_ewm_52h_jw}  

    //Server script
    (function() {
        var portalGr = $sp.getPortalRecord();
        data.logo = portalGr.getDisplayValue("logo");
        data.homepage = portalGr.getDisplayValue("homepage.id");
    })();

    //HTML template
    <div>
        <img ng-src="{{::c.data.logo}}" />
        <a href="?id={{::c.data.homepage}}">Click here to go home</a>
    </div>

## GlideSPScriptable - getRecord(String table, String sys_id) {#ariaid-title20}

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.
{#r_GSPS-getRecord__table_mzs_gfh_jw__entry__3}

| 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. |
[Table 37. Parameters]

{#r_GSPS-getRecord__table_mzs_gfh_jw} {#r_GSPS-getRecord__table_nzs_gfh_jw__entry__2}

| 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. |
[Table 38. Returns]

{#r_GSPS-getRecord__table_nzs_gfh_jw}  

    //Server script 
    (function(){ 
    var now_GR = $sp.getRecord(); 
    data.tableLabel = now_GR.getLabel(); 
    })(); 

    //HTML template 
    <div class="panel-heading"> 
    <h4 class="panel-title">${{{data.tableLabel}} details}</h4> 
    </div>

## GlideSPScriptable - getRecordDisplayValues(Object data, GlideRecord from, String names) {#ariaid-title21}

Copies display values for the specified fields into the data parameter.
{#r_GSPS-getRecordDispValues_O_GR_S__table_xn2_mhh_jw__entry__3}

| 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. |
[Table 39. Parameters]

{#r_GSPS-getRecordDispValues_O_GR_S__table_xn2_mhh_jw} {#r_GSPS-getRecordDispValues_O_GR_S__table_yn2_mhh_jw__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 40. Returns]

{#r_GSPS-getRecordDispValues_O_GR_S__table_yn2_mhh_jw}

## GlideSPScriptable - getRecordElements(Object data, GlideRecord from, String names) {#ariaid-title22}

For the specified fields, copies the element's name, display value, and value into the
data parameter.
{#r_GSPS-getRecordElements_O_GR_S__table_gvx_qkh_jw__entry__3}

| 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. |
[Table 41. Parameters]

{#r_GSPS-getRecordElements_O_GR_S__table_gvx_qkh_jw} {#r_GSPS-getRecordElements_O_GR_S__table_hvx_qkh_jw__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 42. Returns]

{#r_GSPS-getRecordElements_O_GR_S__table_hvx_qkh_jw}

## GlideSPScriptable - getRecordValues(Object data, GlideRecord from, String names) {#ariaid-title23}

Copies values for the specified field names from the GlideRecord into the data
parameter.
{#r_GSPS-getRecordValues_O_GR_S__table_bhn_rlh_jw__entry__3}

| 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. |
[Table 43. Parameters]

{#r_GSPS-getRecordValues_O_GR_S__table_bhn_rlh_jw} {#r_GSPS-getRecordValues_O_GR_S__table_chn_rlh_jw__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 44. Returns]

{#r_GSPS-getRecordValues_O_GR_S__table_chn_rlh_jw}

## GlideSPScriptable - getRecordVariables(GlideRecord now_GR, Boolean includeNilResponses) {#ariaid-title24}

Returns Service Catalog
variables associated with a record in String format.
{#GSPS-getRecordVars_GR_B__table_e5c_jbz_43b__entry__3}

| 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. |
[Table 45. Parameters]

{#GSPS-getRecordVars_GR_B__table_e5c_jbz_43b} {#GSPS-getRecordVars_GR_B__table_f5c_jbz_43b__entry__2}

| Type | Description |
|-|-|
| String | Service Catalog variables associated with the record. |
[Table 46. Returns]

{#GSPS-getRecordVars_GR_B__table_f5c_jbz_43b}  

    //Server script 
    (function() {
    var itemsGR = new GlideRecord("sc_req_item");
    itemsGR.get('585d1bc44f4f13008a959a211310c77d');
    	
    data.scVars = $sp.getRecordVariables(itemsGR);

    })();

    //HTML template
    <div>
    Requested item variables: {{::data.scVars}}
    </div>

Output:

    Requested item variables: [
      {
        "display_value":"MetroPCS",
        "name":"carrier",
        "visible_summary":true,
        "id":"585d1bc44f4f13008a959a211310c77c",
        "label":"Allocated carrier",
        "type":"5",
        "value":"metropcs",
        "visible_standalone":true,
        "visible_guide":true
      },
      {
        "display_value":"Unlimited",
        "name":"data_plan",
        "visible_summary":true,
        "id":"d05d1bc44f4f13008a959a211310c77c",
        "label":"Monthly data allowance",
        "type":"5",
        "value":"unlimited",
        "visible_standalone":true,
        "visible_guide":true
      },
      {
        "display_value":"12 Months",
        "name":"duration",
        "visible_summary":true,
        "id":"d85d1bc44f4f13008a959a211310c77c",
        "label":"Contract duration",
        "type":"5",
        "value":"twelve_months",
        "visible_standalone":true,
        "visible_guide":true
      },
      {
        "display_value":"Slate",
        "name":"color",
        "visible_summary":true,
        "id":"545d1bc44f4f13008a959a211310c77c",
        "label":"Color",
        "type":"5",
        "value":"slate",
        "visible_standalone":true,
        "visible_guide":true
      },
      {"display_value":"64GB",
        "name":"storage",
        "visible_summary":true,
        "id":"d45d1bc44f4f13008a959a211310c77c",
        "label":"Storage",
        "type":"5",
        "value":"sixtyfour",
        "visible_standalone":true,
        "visible_guide":true
      }
    ]

## GlideSPScriptable - getRecordVariablesArray(GlideRecord now_GR, Boolean includeNilResponses) {#ariaid-title25}

Returns an array of Service Catalog variables associated
with a record.
{#GSPS-getRecVarArray_GR__table_tyy_kx3_h2b__entry__3}

| 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. |
[Table 47. Parameters]

{#GSPS-getRecVarArray_GR__table_tyy_kx3_h2b} {#GSPS-getRecVarArray_GR__table_uyy_kx3_h2b__entry__2}

| Type | Description |
|-|-|
| Object | Array of Service Catalog variables associated with the record. |
[Table 48. Returns]

{#GSPS-getRecVarArray_GR__table_uyy_kx3_h2b}  

    //Server script 
    (function() {
    var itemsGR = new GlideRecord("sc_req_item");
    itemsGR.get('585d1bc44f4f13008a959a211310c77d');
    	
    data.scVars = $sp.getRecordVariablesArray(itemsGR);

    })();

    //HTML template
    <div>
    Requested item variables: {{::data.scVars}}
    </div>

Output:

    Requested item variables: [
      {
        "display_value":"MetroPCS",
        "name":"carrier",
        "visible_summary":true,
        "id":"585d1bc44f4f13008a959a211310c77c",
        "label":"Allocated carrier",
        "type":"5",
        "value":"metropcs",
        "visible_standalone":true,
        "visible_guide":true
      },
      {
        "display_value":"Unlimited",
        "name":"data_plan",
        "visible_summary":true,
        "id":"d05d1bc44f4f13008a959a211310c77c",
        "label":"Monthly data allowance",
        "type":"5",
        "value":"unlimited",
        "visible_standalone":true,
        "visible_guide":true
      },
      {
        "display_value":"12 Months",
        "name":"duration",
        "visible_summary":true,
        "id":"d85d1bc44f4f13008a959a211310c77c",
        "label":"Contract duration",
        "type":"5",
        "value":"twelve_months",
        "visible_standalone":true,
        "visible_guide":true
      },
      {
        "display_value":"Slate",
        "name":"color",
        "visible_summary":true,
        "id":"545d1bc44f4f13008a959a211310c77c",
        "label":"Color",
        "type":"5",
        "value":"slate",
        "visible_standalone":true,
        "visible_guide":true
      },
      {"display_value":"64GB",
        "name":"storage",
        "visible_summary":true,
        "id":"d45d1bc44f4f13008a959a211310c77c",
        "label":"Storage",
        "type":"5",
        "value":"sixtyfour",
        "visible_standalone":true,
        "visible_guide":true
      }
    ]

## GlideSPScriptable - getStream(String table, String sysId) {#ariaid-title26}

Gets the activity stream for the specified record. This method works on tables that
extend the task table.
{#r_GSPS-getStream_S_S__table_g5b_jmh_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| table | String | The table name |
| sysID | String | The sys_id of the record |
[Table 49. Parameters]

{#r_GSPS-getStream_S_S__table_g5b_jmh_jw} {#r_GSPS-getStream_S_S__table_h5b_jmh_jw__entry__2}

| 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. |
[Table 50. Returns]

{#r_GSPS-getStream_S_S__table_h5b_jmh_jw}

## GlideSPScriptable - getUserInitials() {#ariaid-title27}

Returns the user's initials.
{#r_GSPS-getUserInitials__table_csj_vmh_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 51. Parameters]

{#r_GSPS-getUserInitials__table_csj_vmh_jw} {#r_GSPS-getUserInitials__table_dsj_vmh_jw__entry__2}

| Type | Description |
|-|-|
| String | The user's initials |
[Table 52. Returns]

{#r_GSPS-getUserInitials__table_dsj_vmh_jw}

## GlideSPScriptable - getValue(String name) {#ariaid-title28}

Returns the named value of the JSON request, instance, or portal.
{#r_GSPS-getValue_S__table_ist_nnh_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Name of the JSON request, instance, or portal. |
[Table 53. Parameters]

{#r_GSPS-getValue_S__table_ist_nnh_jw} {#r_GSPS-getValue_S__table_jst_nnh_jw__entry__2}

| Type | Description |
|-|-|
| Object | Value of the specified parameter. Null if the specified entity does not exist or has no such parameter. |
[Table 54. Returns]

{#r_GSPS-getValue_S__table_jst_nnh_jw}  

    //Server script
    (function() {
        data.title = $sp.getValue("title");
        data.catalog = $sp.getValue("sc_catalog");
    })();

    //HTML templage
    <div>
        <h1>sp_instance.title: {{::data.title}}</h1>
        <h1>sp_portal.sc_catalog: {{::data.catalog}}</h1>
    </div>

## GlideSPScriptable - getValues(Object data, String names) {#ariaid-title29}

Copies values from the request or instance to the data parameter.
{#r_GSPS-getValues_O_S__table_ugp_d4h_jw__entry__3}

| Name | Type | Description |
|-|-|-|
| data | Object | Receives the parameter values. |
| names | String | Comma-separated string of field names. |
[Table 55. Parameters]

{#r_GSPS-getValues_O_S__table_ugp_d4h_jw} {#r_GSPS-getValues_O_S__table_vgp_d4h_jw__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 56. Returns]

{#r_GSPS-getValues_O_S__table_vgp_d4h_jw}

## GlideSPScriptable - getVariablesArray(Boolean includeNilResponses) {#ariaid-title30}

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.
{#GSPS-getVariablesArray__table_yzy_j2p_l3b__entry__3}

| Name | Type | Description |
|-|-|-|
| includeNilResponses | Boolean | Optional. If true, the API includes variables with no user-defined value. |
[Table 57. Parameters]

{#GSPS-getVariablesArray__table_yzy_j2p_l3b} {#GSPS-getVariablesArray__table_ixh_flp_l3b__entry__2}

| Type | Description |
|-|-|
| Object | Array of variables associated with the table. |
[Table 58. Returns]

{#GSPS-getVariablesArray__table_ixh_flp_l3b}  

    //Server script 
    (function() {	
    data.scVars = $sp.getVariablesArray();
    })();

    //HTML template
    <div
    Current record variables: {{::data.scVars}}
    </div>

Output:

    Current record variables: [
      {
        "display_value":"unlimited",
        "name":"data","visible_summary":
        true,"id":"472e5620db4f330083766b984b96198a",
        "label":"Data",
        "type":"6",
        "value":"unlimited",
        "visible_standalone":true,
        "visible_guide":true
      },
      {
        "display_value":"Black",
        "name":"color",
        "visible_summary":true,
        "id":"c72e5620db4f330083766b984b96198a",
        "label":"Color",
        "type":"6",
        "value":"Black",
        "visible_standalone":true,
        "visible_guide":true
      }
    ] 

## GlideSPScriptable - getWidget(String sysID, Object options) {#ariaid-title31}

Gets a widget by id or sys_id, executes that widget's server script using the provided
options, then returns the widget model.
{#r_GSPS-getWidget_S__O__table_vms_1ph_jw__entry__3}

| 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. |
[Table 59. Parameters]

{#r_GSPS-getWidget_S__O__table_vms_1ph_jw} {#r_GSPS-getWidget_S__O__table_wms_1ph_jw__entry__2}

| Type | Description |
|-|-|
| Object | A widget model to be used with sp-widget. |
[Table 60. Returns]

{#r_GSPS-getWidget_S__O__table_wms_1ph_jw}  

    //Server script
    data.myWidget = $sp.getWidget('widget_id', {p1: param1, p2: param2});

    //HTML
    <sp-widget widget="c.data.myWidget"></sp-widget>

## GlideSPScriptable - isRTLEnabled() {#ariaid-title32}

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.
{#GSPS-isRTLEnabled__table_ftx_1c3_yxb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 61. Parameters]

{#GSPS-isRTLEnabled__table_ftx_1c3_yxb} {#GSPS-isRTLEnabled__table_gtx_1c3_yxb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the RTL flag is enabled and the current user's session language is directionally RTL. Possible values: * true: The RTL flag is enabled. * false: The RTL flag isn't enabled. Data type: Boolean |
[Table 62. Returns]

{#GSPS-isRTLEnabled__table_gtx_1c3_yxb}  
The following code example shows how to use this method to determine the type of icon to display on the portal page.

    // Server script  
    (function() {
      data.isRTLEnabled = $sp.isRTLEnabled();
     })(); 

    // HTML template 
    <div> <i ng-class="c.data.isRTLEnabled ? 'fa fa-arrow-right' : 'fa fa-arrow-left'"></i> </div> 

## GlideSPScriptable - isUserCriteriaEnabled() {#ariaid-title33}

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.
{#GSPS-isUserCriteriaEnabled__table_bn5_zzb_x2b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 63. Parameters]

{#GSPS-isUserCriteriaEnabled__table_bn5_zzb_x2b} {#GSPS-isUserCriteriaEnabled__table_cn5_zzb_x2b__entry__2}

| Type | Description |
|-|-|
| Boolean | True if user criteria is enabled. |
[Table 64. Returns]

{#GSPS-isUserCriteriaEnabled__table_cn5_zzb_x2b}

## GlideSPScriptable - log(Object message) {#ariaid-title34}

Logs output to the Service Portal Log Entries \[sp_log\] table. The logged in user must
have the sp_admin or admin role.
{#GSPS-log_O__table_odb_whn_p2b__entry__3}

| Name | Type | Description |
|-|-|-|
| message | Object | JavaScript object or string representing the message to send as output on a Service Portal page. |
[Table 65. Parameters]

{#GSPS-log_O__table_odb_whn_p2b} {#GSPS-log_O__table_pdb_whn_p2b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 66. Returns]

{#GSPS-log_O__table_pdb_whn_p2b}  
The following example shows how to log a predefined error if it occurs.

    var demo_data = null;
    var params = null;
    if (gr.getValue("demo_data")) {
       try {
    	demo_data = JSON.parse(gr.getValue("demo_data"));
    	params = (demo_data.options) ? demo_data.options : null;
    	} catch(e) {
    	$sp.log(e);
       }
    }

## GlideSPScriptable - mapUrlToSPUrl(String url) {#ariaid-title35}

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.
Use this method to perform tasks such as redirecting a user after login to the correct Service Portal page when they request a platform UI form or list URL. Note that the `id=list` and `id=form` page targets are not customizable.  
Note:  
Table, sys_id, and sysparm_query values are preserved from the original URL; sysparm_view is not.
{#GSPS-mapUrlToSPUrl_S__table_odb_whn_p2b__entry__3}

| Name | Type | Description |
|-|-|-|
| url | String | Platform UI URL |
[Table 67. Parameters]

{#GSPS-mapUrlToSPUrl_S__table_odb_whn_p2b} {#GSPS-mapUrlToSPUrl_S__table_pdb_whn_p2b__entry__2}

| 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. |
[Table 68. Returns]

{#GSPS-mapUrlToSPUrl_S__table_pdb_whn_p2b}  
List example

    GlideSPScriptable().mapUrlToSPUrl("http://demo.service-now.com/task_list.do?sysparm_userpref_module=1523b8d4c611227b00be8216ec331b9a&sysparm_query=assigned_to=javascript:getMyAssignments()&sysparm_clear_stack=true"))

Returns

    id=list&table=task&filter=assigned_to=javascript:getMyAssignments()&sys_id=&v=

Form example

    GlideSPScriptable().mapUrlToSPUrl("incident.do?sys_id=12bc12bc12bc12bc12bc12bc12bc12bc")

Returns

    id=form&table=incident&filter=&sys_id=12bc12bc12bc12bc12bc12bc12bc12bc&v=

## GlideSPScriptable - userCanSeeSearchSourceByCriteria(String searchSourceID) {#ariaid-title36}

Returns true if the current user can see a search source specified by the
searchSourceID.
Returns true if the user is not restricted by user criteria. For more detail on how user criteria affects Service Portal assets, see [User criteria for Service
Portal](https://www.servicenow.com/docs/access?context=user-criteria&version=xanadu&pubname=xanadu-platform-user-interface&ft:locale=en-US).  
Note:  
This method does not evaluate role-based permissions of the search source, and should only be used if User Criteria is enabled.
{#GSPS-userCanSeeSearchSourceByCriteria__table_jjl_cjc_x2b__entry__3}

| Name | Type | Description |
|-|-|-|
| searchSourceID | String | Sys_id of the search source record. |
[Table 69. Parameters]

{#GSPS-userCanSeeSearchSourceByCriteria__table_jjl_cjc_x2b} {#GSPS-userCanSeeSearchSourceByCriteria__table_kjl_cjc_x2b__entry__2}

| Type | Description |
|-|-|
| Boolean | True if current user has read access to the search source. |
[Table 70. Returns]

{#GSPS-userCanSeeSearchSourceByCriteria__table_kjl_cjc_x2b}

