Redirect Existing URL to new URL when page is loaded in servicenow

vikas41
Tera Contributor

Hi Everyone
I need some help redirecting to the new URL.
Example :- "catalog_home.do?sysparm_view=catalog_default" .
As per the above Example, I need users to redirect the new URL to "/sp" when they open the URL in the example.

1 ACCEPTED SOLUTION

@vikas41 

yes you can do this to that OOB UI page, But I won't recommend touching OOB UI page unless it's required

1) when user navigates to that UI page, simply show alert and take them to sp portal page

Here is the updated UI page and working output

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<!--
  catalog homepage
-->
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<body onload="informUser()">

  <g:requires name="scripts/js_includes_listv2.js" includes="true"/>
  <g:requires name="scripts/js_includes_catalog.js" includes="true"/>
  <g:evaluate var="jvar_theme">
	var theme = gs.getPreference('glide.css.theme.ui16');
	if (null == theme){
		var company = gs.getUser().getCompanyRecord();
		if (null != company)
		theme = company.getValue("theme");
	}
	theme;
  </g:evaluate>
  <g:requires name="styles/${new CatalogCssSelector().getVariableCss()}" includes="true" params="theme=${jvar_theme}"/>
  <g:if_polaris>
     <g:then>
        <g:requires name="styles/${new CatalogCssSelector().getPolarisVariableCss()}" includes="true" params="theme=${jvar_theme}"/>
     </g:then>
  </g:if_polaris>
  <g:requires name="styles/${new CatalogCssSelector().getCatalogCss()}" includes="false" params="theme=${jvar_theme}"/>
  <g:if_polaris>
     <g:then>
        <g:requires name="styles/${new CatalogCssSelector().getPolarisCatalogCss()}" includes="false" params="theme=${jvar_theme}"/>
     </g:then>
  </g:if_polaris>
  <g:inline template="sc_sanitize.xml"/>
  <g:inline template="glide_weba_header.xml" />
  <g2:evaluate expression="SNC.CatalogURLGenerator.clearBrowsingContextCategoryID()" />
  <g:evaluate jelly="true">
     var catalog = jelly.sysparm_catalog + "";
     var catalog_view = jelly.sysparm_catalog_view + "";
     var view = jelly.sysparm_view + "";
     var re = /^[0-9A-Fa-f]{32}$/g;
     if (JSUtil.nil(catalog.match(re)))
        catalog = "";
     var rev = /^[0-9A-Za-z_]+$/g;
     if (JSUtil.nil(view.match(rev)))
        view = "";
     if (JSUtil.nil(catalog_view.match(rev)))
        catalog_view = "";
     var temp_catalog_view = GlideappCatalogURLGenerator.getCatalogViewForHome(catalog, catalog_view, view);
     var temp_catalog = GlideappCatalogURLGenerator.getCatalogForHome(catalog, catalog_view, view);
     catalog_view = temp_catalog_view;
     catalog = temp_catalog;
     view = catalog_view;
     
     var layout = "022ac9000a0a0b120041878ff6ceb99b";
     var layoutName = "layout_3_across_catalog";
     var gr = new GlideRecord('sys_portal_page');
	 gr.addQuery('view', view);
	 gr.query();
	 if (gr.next()) {
	    layout = gr.layout.sys_id + "";
	    layoutName = gr.layout.name + "";
     }
  </g:evaluate>
  <g:inline template="sc_request_parent_message.xml"/>
  <input type="HIDDEN" id="sysparm_catalog" value="${catalog}"/>
  <input type="HIDDEN" id="sysparm_catalog_view" value="${catalog_view}"/>
  <j:set var="sysparm_catalog" value="${catalog}"/>
  <j:set var="sysparm_catalog_view" value="${catalog_view}"/>
  <j:set var="sysparm_view" value="${catalog_view}"/>
  <j:set var="sysparm_parent" value=""/>
  <j2:set var="sysparm_catalog" value="${catalog}"/>
  <j2:set var="sysparm_catalog_view" value="${catalog_view}"/>
  <j2:set var="sysparm_view" value="${view}"/>
  <j2:set var="sysparm_parent" value=""/>
  <j:set var="jvar_is_catalog" value="${true}"/>
  <j2:set var="jvar_gridName" value="homepage_grid"/>
  <g2:evaluate jelly="true">
     var hu = new GlideappHome(jelly);
     var current_page = hu.getCurrentPage();
  </g2:evaluate>
  <style>
     TABLE {
        white-space: normal;
     }
  </style>
  <g:messages>
     Close
     Edit
     Collapse
     Shopping Cart
     Empty
     Edit Cart
     Continue Shopping
     Proceed to Checkout
     Save and Checkout
  </g:messages>         
  <g:inline template="grid_header.xml"/>
  <g2:evaluate var="jvar_editable_grid" jelly="true">
	  var edit_access = gs.hasRole('catalog_admin');
	  if(!edit_access $[AMP]$[AMP] gs.hasRole('catalog_manager')){
		  var gr = new GlideRecord('sc_catalog');
		  gr.get(catalog);
		  var manager = gr.getValue("manager");
		  if (manager==gs.getUserID())
			  edit_access = true;
	  }
	  if(!edit_access $[AMP]$[AMP] gs.hasRole('catalog_editor')){
		  var gr = new GlideRecord('sc_catalog');
		  gr.get(catalog);
		  var editors = gr.getValue("editors");
		  if (editors $[AMP]$[AMP] editors.indexOf(gs.getUserID()) != -1)
			  edit_access = true;
	  }
    jelly.jvar_editable_grid $[AMP]$[AMP] edit_access $[AMP]$[AMP] !GlideMobileExtensions.runningTablet();
  </g2:evaluate>
  <g2:evaluate var="jvar_editable_content">
     edit_access $[AMP]$[AMP] !GlideMobileExtensions.runningTablet();
  </g2:evaluate>
  <g:inline template="catalog_title_editor.xml" />

  <j:if test="${new GlideappScriptHelper().isUI16Enabled()}">
    <script>
      catalogHistory.setHistory('$[HTML,JS:jvar_catalog_title]', catalogHistory.getPageUrl());
    </script>
  </j:if>

  <!-- layout -->
  <g2:call function="${layoutName}.xml" name="$[jvar_gridName]"/>
    
  <!-- pre-rendered content -->
  <j2:if test="$[JSUtil.notNil(current_page.getID())]">
	  <g2:generate_grid id="$[current_page.getID()]" editable="$[jvar_editable_content]"/>
  </j2:if>

  <g:inline template="grid_script.xml"/>
  <g2:call function="grid_footer.xml" editable="$[jvar_editable_grid]" name="$[jvar_gridName]" view="$[sysparm_view]"/>

  <script>
     addLateLoadEvent(function() {
		focusOnSearch();
	    var base = previewLayoutID;
        previewLayoutID = function(id, mode) {
           id = "${layout}";
           base(id, mode);
        }
     });

	function addHomeContent() {
		var page_id = glideGrid.getProperty('sys_id');
		var name = "${layout}";
		var title = "${gs.getMessage('Sections')}";
		var filter = "$[gs.getProperty('glide.sc.home.filter')]";
		var catalog_id = '$[catalog]';
		var catalog_view = '$[catalog_view]';
		sectionDialog({
			name : name,
			renderer : SECTIONS,
			title : title,
			filter : filter,
			page_id : page_id,
			pinned : true,
			catalog_id : catalog_id,
			catalog_view : catalog_view,
			focusTrap: true
		});
	}
	function focusOnSearch() {
	  var elemSearchInput = document.getElementsByClassName("scSearchInput");
	  if (elemSearchInput $[AMP]$[AMP] elemSearchInput.length > 0)
		  elemSearchInput[0].focus();
	  
	}
  </script>
 <g:inline template="catalog_web_analytics.xml" />
 </body>
 </html>
</j:jelly>

Client Script:

function informUser(){
	alert('Please use sp portal page to submit request');
	top.location.href = '/sp';
}

Output:

ui page.gif

I hope I have answered your question and you can enhance it further now

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

@vikas41 

yes you can do this to that OOB UI page, But I won't recommend touching OOB UI page unless it's required

1) when user navigates to that UI page, simply show alert and take them to sp portal page

Here is the updated UI page and working output

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<!--
  catalog homepage
-->
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<body onload="informUser()">

  <g:requires name="scripts/js_includes_listv2.js" includes="true"/>
  <g:requires name="scripts/js_includes_catalog.js" includes="true"/>
  <g:evaluate var="jvar_theme">
	var theme = gs.getPreference('glide.css.theme.ui16');
	if (null == theme){
		var company = gs.getUser().getCompanyRecord();
		if (null != company)
		theme = company.getValue("theme");
	}
	theme;
  </g:evaluate>
  <g:requires name="styles/${new CatalogCssSelector().getVariableCss()}" includes="true" params="theme=${jvar_theme}"/>
  <g:if_polaris>
     <g:then>
        <g:requires name="styles/${new CatalogCssSelector().getPolarisVariableCss()}" includes="true" params="theme=${jvar_theme}"/>
     </g:then>
  </g:if_polaris>
  <g:requires name="styles/${new CatalogCssSelector().getCatalogCss()}" includes="false" params="theme=${jvar_theme}"/>
  <g:if_polaris>
     <g:then>
        <g:requires name="styles/${new CatalogCssSelector().getPolarisCatalogCss()}" includes="false" params="theme=${jvar_theme}"/>
     </g:then>
  </g:if_polaris>
  <g:inline template="sc_sanitize.xml"/>
  <g:inline template="glide_weba_header.xml" />
  <g2:evaluate expression="SNC.CatalogURLGenerator.clearBrowsingContextCategoryID()" />
  <g:evaluate jelly="true">
     var catalog = jelly.sysparm_catalog + "";
     var catalog_view = jelly.sysparm_catalog_view + "";
     var view = jelly.sysparm_view + "";
     var re = /^[0-9A-Fa-f]{32}$/g;
     if (JSUtil.nil(catalog.match(re)))
        catalog = "";
     var rev = /^[0-9A-Za-z_]+$/g;
     if (JSUtil.nil(view.match(rev)))
        view = "";
     if (JSUtil.nil(catalog_view.match(rev)))
        catalog_view = "";
     var temp_catalog_view = GlideappCatalogURLGenerator.getCatalogViewForHome(catalog, catalog_view, view);
     var temp_catalog = GlideappCatalogURLGenerator.getCatalogForHome(catalog, catalog_view, view);
     catalog_view = temp_catalog_view;
     catalog = temp_catalog;
     view = catalog_view;
     
     var layout = "022ac9000a0a0b120041878ff6ceb99b";
     var layoutName = "layout_3_across_catalog";
     var gr = new GlideRecord('sys_portal_page');
	 gr.addQuery('view', view);
	 gr.query();
	 if (gr.next()) {
	    layout = gr.layout.sys_id + "";
	    layoutName = gr.layout.name + "";
     }
  </g:evaluate>
  <g:inline template="sc_request_parent_message.xml"/>
  <input type="HIDDEN" id="sysparm_catalog" value="${catalog}"/>
  <input type="HIDDEN" id="sysparm_catalog_view" value="${catalog_view}"/>
  <j:set var="sysparm_catalog" value="${catalog}"/>
  <j:set var="sysparm_catalog_view" value="${catalog_view}"/>
  <j:set var="sysparm_view" value="${catalog_view}"/>
  <j:set var="sysparm_parent" value=""/>
  <j2:set var="sysparm_catalog" value="${catalog}"/>
  <j2:set var="sysparm_catalog_view" value="${catalog_view}"/>
  <j2:set var="sysparm_view" value="${view}"/>
  <j2:set var="sysparm_parent" value=""/>
  <j:set var="jvar_is_catalog" value="${true}"/>
  <j2:set var="jvar_gridName" value="homepage_grid"/>
  <g2:evaluate jelly="true">
     var hu = new GlideappHome(jelly);
     var current_page = hu.getCurrentPage();
  </g2:evaluate>
  <style>
     TABLE {
        white-space: normal;
     }
  </style>
  <g:messages>
     Close
     Edit
     Collapse
     Shopping Cart
     Empty
     Edit Cart
     Continue Shopping
     Proceed to Checkout
     Save and Checkout
  </g:messages>         
  <g:inline template="grid_header.xml"/>
  <g2:evaluate var="jvar_editable_grid" jelly="true">
	  var edit_access = gs.hasRole('catalog_admin');
	  if(!edit_access $[AMP]$[AMP] gs.hasRole('catalog_manager')){
		  var gr = new GlideRecord('sc_catalog');
		  gr.get(catalog);
		  var manager = gr.getValue("manager");
		  if (manager==gs.getUserID())
			  edit_access = true;
	  }
	  if(!edit_access $[AMP]$[AMP] gs.hasRole('catalog_editor')){
		  var gr = new GlideRecord('sc_catalog');
		  gr.get(catalog);
		  var editors = gr.getValue("editors");
		  if (editors $[AMP]$[AMP] editors.indexOf(gs.getUserID()) != -1)
			  edit_access = true;
	  }
    jelly.jvar_editable_grid $[AMP]$[AMP] edit_access $[AMP]$[AMP] !GlideMobileExtensions.runningTablet();
  </g2:evaluate>
  <g2:evaluate var="jvar_editable_content">
     edit_access $[AMP]$[AMP] !GlideMobileExtensions.runningTablet();
  </g2:evaluate>
  <g:inline template="catalog_title_editor.xml" />

  <j:if test="${new GlideappScriptHelper().isUI16Enabled()}">
    <script>
      catalogHistory.setHistory('$[HTML,JS:jvar_catalog_title]', catalogHistory.getPageUrl());
    </script>
  </j:if>

  <!-- layout -->
  <g2:call function="${layoutName}.xml" name="$[jvar_gridName]"/>
    
  <!-- pre-rendered content -->
  <j2:if test="$[JSUtil.notNil(current_page.getID())]">
	  <g2:generate_grid id="$[current_page.getID()]" editable="$[jvar_editable_content]"/>
  </j2:if>

  <g:inline template="grid_script.xml"/>
  <g2:call function="grid_footer.xml" editable="$[jvar_editable_grid]" name="$[jvar_gridName]" view="$[sysparm_view]"/>

  <script>
     addLateLoadEvent(function() {
		focusOnSearch();
	    var base = previewLayoutID;
        previewLayoutID = function(id, mode) {
           id = "${layout}";
           base(id, mode);
        }
     });

	function addHomeContent() {
		var page_id = glideGrid.getProperty('sys_id');
		var name = "${layout}";
		var title = "${gs.getMessage('Sections')}";
		var filter = "$[gs.getProperty('glide.sc.home.filter')]";
		var catalog_id = '$[catalog]';
		var catalog_view = '$[catalog_view]';
		sectionDialog({
			name : name,
			renderer : SECTIONS,
			title : title,
			filter : filter,
			page_id : page_id,
			pinned : true,
			catalog_id : catalog_id,
			catalog_view : catalog_view,
			focusTrap: true
		});
	}
	function focusOnSearch() {
	  var elemSearchInput = document.getElementsByClassName("scSearchInput");
	  if (elemSearchInput $[AMP]$[AMP] elemSearchInput.length > 0)
		  elemSearchInput[0].focus();
	  
	}
  </script>
 <g:inline template="catalog_web_analytics.xml" />
 </body>
 </html>
</j:jelly>

Client Script:

function informUser(){
	alert('Please use sp portal page to submit request');
	top.location.href = '/sp';
}

Output:

ui page.gif

I hope I have answered your question and you can enhance it further now

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Hi @vikas41,

 

For page routing, you can utilize the Page Route Maps table. This is an out-of-the-box (OOB) table that manages all routing configurations.


image.png

 

Mark this as Helpful / Accept the Solution if this helps so that it helps future hunters.

@Community Alums 
Hi Divesh
Page route maps are used to redirect service portal pages.
But my requirement is used to redirect from '"UI page" to "Service portal".(Platform view to portal view)

My requirement is to redirect to "/sp" from below image link as highlighted.

vikas41_1-1741261661672.png

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @vikas41 

 

You can use the Page route maps.

 

https://www.servicenow.com/docs/bundle/yokohama-employee-service-management/page/product/human-resou...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

@Dr Atul G- LNG 
Page route maps are used to redirect service portal pages.
But my requirement is used to redirect from '"UI page" to "Service portal".(Platform view to portal view)

My requirement is to redirect to "/sp" from below image link as highlighted.

vikas41_1-1741261661672.png