{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":902,"path":"api-reference/server-api-reference/SPSEOUtilsSNCAPI.md","title":"SPSEOUtilsSNC - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# SPSEOUtilsSNC- Global\n\nThe SPSEOUtilsSNC script include provides utility methods that return human-readable URLs for a specific page, or for the current page, based on the transaction request.\n\nIn addition, this API provides other utility methods that you can use to obtain information that is needed to call other human-readable URL methods.\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## SPSEOUtilsSNC - getHumanReadableUrl\\(GlideRecord pageGR, String queryString\\)\n\nReturns the human-readable URL for a specified record in the Page \\[sp\\_page \\] table. Uses the passed-in query parameters to resolve any dynamic page variables required by the URL.\n\n<table id=\"table_vjm_wwg_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 the record in the Page \\[sp\\_page\\] table for which to return the human-readable URL.Use the [SPSEOUtilsSNC - getPageRecordWithPageRoute\\(GlideRecord pageId, String portalId, Boolean preventReRoute\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/SPSEOUtilsSNCAPI.md) method to obtain the desired sp\\_page GlideRecord.\n\n</td></tr><tr><td>\n\nqueryString\n\n</td><td>\n\nString\n\n</td><td>\n\nQuery string to use to resolve any parameters that may need to be passed by the URL. For example: `?id=kb_article&sys_id=471ee81eff6002009b20ffffffffff34`\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Human-readable URL for the specified Service Portal record. The URL variables are resolved using the contents of the passed **queryString** parameter.|\n\nThe following code example shows how to call this method to obtain the human-readable URL.\n\n```\nfunction() { \n  var util = new global.SPSEOUtilsSNC();\n  var portalId = util.getPortalId();\n  var pageGR = util.getPageRecordWithPageRoute(\n    'kb_article', portalId, false); \n  var queryString = \"?id=kb_article&sys_id=471ee81eff6002009b20ffffffffff34\"; \n  var hrUrl = util.getHumanReadableUrl(pageGR, queryString);\n```\n\nOutput:\n\n```\n\"getting-around-in-windows\"\n```\n\n## SPSEOUtilsSNC - getHumanReadableUrlForCurrentRequest\\(\\)\n\nReturns the human-readable URL for the current Service Portal record.\n\nThis method replicates the parameters in the cryptic URL of the current page, such as the **id** parameter and the query parameters, when creating this human-readable URL.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Human-readable URL for the current Service Portal record.|\n\nThe following code example shows how to call this method. In this example, the current Service Portal record uses the cryptic URL of `<instance-url>/sp?id=kb_article&sys_id=471ee81eff6002009b20ffffffffff34` and is configured to show the short description of a KB article that discusses navigation in Windows. The returned human-readable URL for this cryptic URL is \"getting-around-in-windows\".\n\n```\n// In a script include\nfunction() {\n  var util = new global.SPSEOUtilsSNC()\n  var hrUrl = util.getHumanReadableUrlForCurrentRequest();\n}\n```\n\nOutput:\n\n```\ngetting-around-in-windows\n```\n\n## SPSEOUtilsSNC - getPageRecordWithPageRoute\\(GlideRecord pageId, String portalId, Boolean preventReRoute\\)\n\nReturns the GlideRecord from the Pages \\[sp\\_page\\] table whose ID field matches the passed ID parameter \\(**pageId**\\). Call this method prior to calling the getHumanReadableUrl\\(\\) method to obtain the desired sp\\_pages GlideRecord.\n\nYou can also request that the method use the page route maps information to return the GlideRecord of the final Service Portal page associated with the passed Service Portal page ID. For additional information on page route maps, see [Redirect a reference to a page ID](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/reroute-page.md).\n\n<table id=\"table_hhx_rzn_tvb\" 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\npageId\n\n</td><td>\n\nString\n\n</td><td>\n\nID of the Pages \\[sp\\_page\\] record to return. Table: In the id field of the Pages \\[sp\\_page\\] table.\n\n</td></tr><tr><td>\n\nportalId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the associated Service Portal \\[sp\\_portal\\] record. Required to return the appropriate login or 404 pages in case the record associated with the passed **pageId** parameter is not accessible or unavailable.Use the [SPSEOUtilsSNC - getPortalId\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/SPSEOUtilsSNCAPI.md) method to obtain the desired Service Portal ID.\n\n</td></tr><tr><td>\n\npreventReRoute\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to use page route maps to return the GlideRecord for the last sp\\_page that the passed page ID resolves to, instead of the matching sp\\_page record.Possible values:\n\n-   true: Use the page route maps to return the last sp\\_page record that the passed page ID resolves to.\n-   false: Return the sp\\_page record that the passed page ID matches.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|GlideRecord|Record that matches the query request for the sp\\_page record.|\n\nThe following code example shows how to call this method prior to calling the getHumanReadableUrl\\(\\) method.\n\n```\nfunction() { \n  var util = new global.SPSEOUtilsSNC();\n  var portalId = util.getPortalId();\n  var pageGR = util.getPageRecordWithPageRoute(\n    'kb_article', portalId, false); \n  var queryString = \"?id=kb_article&sys_id=471ee81eff6002009b20ffffffffff34\"; \n  var hrUrl = util.getHumanReadableUrl(pageGR, queryString);\n```\n\n## SPSEOUtilsSNC - getPortalId\\(\\)\n\nReturns the sys\\_id of the portal being loaded based on the portal suffix in the request URL. Call this method prior to calling the getPageRecordWithPageRoute\\(\\) method to obtain the desired Service Portal sys\\_id.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the requested Service Portal based on the portal suffix of the request URL.|\n\nThe following code example shows how to call this method for a URL such as `<instance-url>/sp?id=index`.\n\n```\nfunction() { \n  var util = new global.SPSEOUtilsSNC();\n  var portalId = util.getPortalId();\n  var pageGR = util.getPageRecordWithPageRoute(\n    'kb_article', portalId, false); \n  var queryString = \"?id=kb_article&sys_id=471ee81eff6002009b20ffffffffff34\"; \n  var hrUrl = util.getHumanReadableUrl(pageGR, queryString);\n```\n\nOutput:\n\n```\n81b75d3147032100ba13a5554ee4902b\n```\n\n"}}