{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":875,"path":"api-reference/server-api-reference/PolarisUIScopedAPI.md","title":"PolarisUI - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# PolarisUI- Scoped\n\nThe PolarisUI API provides methods for enabling Next Experience on direct UI pages.\n\nA UI page \\[sys\\_ui\\_page\\] is direct if the **Direct** field is **Selected**. A direct UI page doesn't include the common HTML page template and must include all CSS and JavaScript that you want to use in the page.\n\nAll non-direct UI pages use Next Experience by default.\n\nFor more information about Next Experience, see [the Next Experience UI](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/next-experience-landing-page.md).\n\nThe PolarisUI API is provided within the `sn_ui` namespace.\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## PolarisUI - canUsePolarisCSS\\(\\)\n\nChecks if the current page can use the Next Experience UI.\n\nThis method returns `true` if all of the following conditions are met.\n\n-   sn\\_ui.PolarisUI.isEnabled\\(\\) is `true`.\n-   The request URL parameter **sysparm\\_use\\_polaris** is not set to `false`.\n-   The referrer HTTP request header does not contain `sysparm_use_polaris=false`.\n-   The page or its parent plugin are not denied use of Next Experience by a record in the Page Theme Support \\[sys\\_page\\_theme\\] table.\n\nUse this method to conditionally change behavior or [jelly](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/r_JellyTags.md) output if Next Experience is enabled.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_wzz_nkq_prb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the current page can use the Next Experience UI.\n\n Valid values:\n\n-   true: The current page can use the Next Experience UI.\n-   false: The current page can't use the Next Experience UI.\n\n</td></tr></tbody>\n</table>This UI Action redirects to a different page if Next Experience is running on the current form.\n\n```\nvar id = current.getUniqueValue();\nif (sn_ui.PolarisUI.canUsePolarisCSS())\n\taction.setRedirectUrl(\"/now/custom/application/record/\" + id);\nreturn \"/record.do?sys_id=\" + id;\n\n```\n\nThis jelly script sets a different style sheet for pages using Next Experience.\n\n```\n<g:evaluate var=\"jvar_css_path\">\n\t// Core UI content css record\n\tvar id = \"5e8fde63d713310074304187ed61030d\";\n\n\tif (sn_ui.PolarisUI.canUsePolarisCSS())\n\t\tid = \"84f03cc87120a00cfab6dd207cb0b72\";\n\t\n\t\"/\" + id + \".cssdbx\";\n</g:evaluate>\n<link href=\"${jvar_css_path}\" rel=\"stylesheet\" type=\"text/css\" />\n\n```\n\n## PolarisUI - getBodyClassNames\\(\\)\n\nReturns a list of CSS class names used by the Next Experience UI.\n\nUse this method in the HTML `<body>` tag of a UI page to set the CSS classes required for Next Experience to render correctly.\n\n```\n<body class=\"$[sn_ui.PolarisUI.getBodyClassNames()]\">\n```\n\nThe returned class names change depending on system properties and if session debug output exists.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|List of CSS class names used by the Next Experience UI.|\n\nThis jelly script adds Next Experience to a custom UI page.\n\n```\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<j:jelly trim=\"true\" xmlns:j=\"jelly:core\" xmlns:g=\"glide\" xmlns:g2=\"null\">\n    <g2:doctype name=\"html\" />\n    <g:inline template=\"dir_checker.xml\"/>\n    <html class=\"${jvar_text_direction}\" lang=\"$[gs.getSession().getLanguage()]\">\n        <head>\n            <g:inline template=\"set_theme_vars.xml\" /> <!-- sets jvar_theme and jvar_css_cache_key -->\n            <g:requires name=\"styles/css_includes_my_app.css\" includes=\"true\" params=\"$[jvar_css_cache_key]\" /> \n            <g:if_polaris>\n\t<g:then><g:inline template=\"polarisberg_output.xml\"/></g:when>\n\t<g:else><g:inline template=\"heisenberg_output.xml\" type=\"css\"/></g:else>\n             </g:if_polaris>\n        </head>\n        <body class=\"$[sn_ui.PolarisUI.getBodyClassNames()]\">\n            Your UI page content here\n        </body>\n    </html>\n</j:jelly>\n```\n\n## PolarisUI - isEnabled\\(\\)\n\nChecks if the Next Experience UI is enabled for the current user.\n\nThis method checks if the **glide.ui.polaris.experience** system property and **glide.ui.polaris.use** user preference are both set to **true**.\n\n-   **glide.ui.polaris.experience** enables Next Experience on the instance.\n-   **glide.ui.polaris.use** disables Next Experience for specified users when set to **false**.\n\nFor more information about Next Experience system properties and user preferences, see [Next Experience system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/pol-sys-properties.md).\n\n**Note:** This method returns true even if Next Experience is disabled for the current page. This method is useful for conditionally enabling entire experiences or redirecting to different pages when Next Experience is enabled globally.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_mjc_djq_prb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the Next Experience UI is enabled for the current user.\n\n Valid values:\n\n-   true: The Next Experience UI is enabled for the current user.\n-   false: The Next Experience UI isn't enabled for the current user.\n\n</td></tr></tbody>\n</table>This UI page displays a conditional message to the user if Next Experience is enabled for the current user.\n\n```\n<j:if test=\"${sn_ui.PolarisUI.isEnabled()}\">\n\t<a href=\"...\">Click here to learn more about the new UI changes</a>\n</j:if>\n```\n\nThis business rule shows an info message on record display that a user can click to view the record in Core UI instead of Next Experience. The business rule **Condition** field is set to `!current.isNewRecord() && sn_ui.PolarisUI.isEnabled() && sn_ui.PolarisUI.canUsePolarisCSS()`.\n\n```\n// business rule script field\n\n(function executeRule(current, previous /*null when async*/) {\n\n\tvar sysId = current.getUniqueValue();\n\tgs.addInfoMessage(\"<a href='/incident.do?sys_id=\"+ sysId +\"&sysparm_use_polaris=false'>Click here to load this page in Core UI</a>\");\n\n})(current, previous);\n\n```\n\n"}}