{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":811,"path":"api-reference/server-api-reference/GlideSPUtilAPI.md","title":"GlideSPUtil - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideSPUtil- Global\n\nThe GlideSPUtil API provides utility methods to perform common backend functions that support a Service Portal.\n\nAvailable utility methods:\n\n-   Resolve variables specified in the Dynamic page variables \\[sp\\_page\\_title\\_variable\\] table associated with a specified Service Portal page located in the Page \\[sp\\_page\\] table.\n-   Other methods\n\nFor additional information, see [Service Portal pages](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/add-human-readable-keywords-page-urls.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideSPUtil - GlideSPUtil\\(\\)\n\nInstantiates a GlideSPUtil object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| ||\n\nThe following code example shows how to instantiate a GlideSPUtil object before calling any of its associated methods.\n\n```\nfunction() {\n  var spUtil = new GlideSPUtil();\n  var pageGR = spUtil.getPageRecordWithPageRoute('kb_article', '81b75d3147032100ba13a5554ee4902b', false);\n  var queryParams = RP.getParameters();\n  var hrUrl = spUtil.getHumanReadableUrl(pageGR, queryParams);\n}\n```\n\n## GlideSPUtil - getHumanReadableUrl\\(\\)\n\nConsiders ‘id’ query parameter to identify the portal page \\(pageGR\\) and uses query string of the current transaction to call getHumanReadableUrl\\(GlideRecord pageGR, String queryString\\) and returns the final human readable.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Human readable URL for the specified Service Portal record with the variables replaced with the contents of the **queryParams** string map.|\n\nThe following code example shows how to.\n\n```\nfunction() {\n  var spUtil = new GlideSPUtil();\n  var hrUrl = spUtil.getHumanReadableUrl();\n}\n```\n\nOutput:\n\n```\n\n```\n\n## GlideSPUtil - getHumanReadableUrl\\(GlideRecord pageGR, String queryParams\\)\n\nConverts the passed **queryParms** string parameter into a string map and then resolves the variables in the \"Human readable url structure\" string provided in the sp\\_page record and returns the final human readable part of the URL.\n\n|Name|Type|Description|\n|----|----|-----------|\n|pageGR|GlideRecord|GlideRecord object of the record in the Page \\[sp\\_page\\] table on which to resolve the URL variables.|\n|queryString|String|Query string.|\n\n|Type|Description|\n|----|-----------|\n|String|Human readable URL for the specified Service Portal record with the variables replaced with the contents of the **queryParams** string map.|\n\nThe following code example shows how to.\n\n```\nfunction() {\n  var spUtil = new GlideSPUtil();\n  var pageGR = spUtil.getPageRecordWithPageRoute('kb_article', '81b75d3147032100ba13a5554ee4902b', false);\n  var queryString = GlideTransaction.get().getRequest().getQueryString();\n  var hrUrl = spUtil.getHumanReadableUrl(pageGR, queryParams);\n}\n```\n\nOutput:\n\n```\n\n```\n\n## GlideSPUtil - getHumanReadableUrl\\(GlideRecord pageGR, StringMap queryParams\\)\n\nResolves the variables in the **Human readable url structure** field of the passed-in Service Portal template page object and returns a URL containing the specified query parameters and the resolved human readable parameters.\n\nUse human readable keywords in a URL to:\n\n-   Enable your customers to better understand the purpose of the URL when it is not in the context of the associated page.\n-   Provide search engines with keywords to better locate the page.\n\nFor example, instead of just having a URL that contains unrecognisable key-value pairs such as this:\n\n`https://instance_name.servicenow.com/sp/en?id=sc_cat_item&sys_id=ec80c13297968d1021983d1e6253af32&sysparm_catgory=1e80c15697969f1032083d1e6253be15`\n\nYou can add the item name to the URL so it is easier to understand the purpose of the URL:\n\n`https://instance_name.servicenow.com/sp/en/apple-iphone-13?id=sc_cat_item&sys_id=ec80c13297968d1021983d1e6253af32&sysparm_catgory=1e80c15697969f1032083d1e6253be15`\n\nBefore you can use this method, you must define the dynamic page variables that are available for each of the Service Portal templates for which you want to include dynamic content in the URL. For details on adding these variables, see [Add human readable keywords to page URLs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/add-human-readable-keywords-page-urls.md).\n\n<table id=\"table_dht_dpg_hvb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\npageGR\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nGlideRecord object of theService Portal template page for which to resolve the dynamic URL variables. Table: Page \\[sp\\_page\\]\n\n</td></tr><tr><td>\n\nqueryParams\n\n</td><td>\n\nStingMap\n\n</td><td>\n\nURL query parameters to use to obtain the desired Service Portal page.For example:\n\n```\n{\n  \"id\": \"sc_cat_item\",\n  \"sys_id\": \"ec80c13297968d1021983d1e6253af32\",\n  \"sysparm_catgory\": \"1e80c15697969f1032083d1e6253be15\"\n}\n```\n\n</td></tr></tbody>\n</table><table id=\"table_eht_dpg_hvb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nURL containing the resolved human readable elements for the dynamic variables specified in the Service Portal template page. For example, if the defined dynamic variable is **%item\\_name**, the URL contains the name of the item that the user selected, such as \"apple-iphone-13, and all of the specified query parameters:\n\n`https://instance_name.servicenow.com/sp/en/apple-iphone-13?id=sc_cat_item&sys_id=ec80c13297968d1021983d1e6253af32&sysparm_catgory=1e80c15697969f1032083d1e6253be15`.\n\n</td></tr></tbody>\n</table>The following code example shows how to obtain a specific KB article and call the getHumanReaadableUrl\\(\\) to apply the associated dynamic variables.\n\n```\nfunction() {\n  var spUtil = new GlideSPUtil();\n  var pageGR = spUtil.getPageRecordWithPageRoute('kb_article', '81b75d3147032100ba13a5554ee4902b', false);\n  var queryParams = RP.getParameters();\n  var hrUrl = spUtil.getHumanReadableUrl(pageGR, queryParams);\n}\n```\n\n"}}