Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to redirect URL in servicenow

sam1212
Mega Expert

Hi ALL,

Some users are trying to use   https://Instance.service-now.com/incident.do or     https://instance.service-now.com/incident.do?sysparm_stack=incident_list.do&sys_id=-1   to create incident is it possible to navigate to different URL(catalog URL)

Any help is appreciated

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

In previous releases, interceptor could have taken care of this but it is legacy now.



I assume you are using record producer or catalog to create the records. If that is the case, I can suggest a workaround for this.



  • Create a display business rule on the table with the below condition
    • current.isNewRecord()
    • Set the value to scratchpad to indicate that the new record was accessed directly.
      • g_scratchpad.invalid_access='true';
  • Create/reuse any existing onload client script on the table and use something like below to redirect.

                  if(g_scratchpad.invalid_access=='true')


                                {


                                          alert("Access to this form is denied");


                                          window.location.href = 'com.glideapp.servicecatalog_category_view.do?v=1&sysparm_parent=e15706fc0a0a0aa7007fc21e1ab70c2f&sysparm_catalog=e0d08b13c3330100c8b837659bba8fb';


                                }


View solution in original post

6 REPLIES 6

It worked


Rajiv Handa
ServiceNow Employee
ServiceNow Employee

You can create a navigator record (sys_navigator) for the incident table and write the server-side script in it to handle which user roles should be allowed to visit the incident table and whom to restrict and redirect to another URL . 

You might have noticed the same behaviour with the sys_hub_flow table, which always redirects the user to the flow designer irrespective of whether the record is opened from the list view or directly from the URL. 

Have a look at the sample script available on

https://www.yourInstanceName.service-now.com/sys_navigator.do?sys_id=07bd077d53632300eb7c0a1806dc34e... 

 

 

(function() {
	var view = g_request.getParameter('sysparm_view');
	if (!gs.nil(view) && view == "manage_security")
		return "";

	if (gs.hasRole('maint'))
		return;

	var sysId = g_request.getParameter('sys_id');
	if (!gs.nil(sysId) && isValidSysHubFlow(sysId)) 
		return g_uri.toString('$flow-designer.do?sysparm_nostack=true#/flow-designer/' + sysId);
	
	return g_uri.toString('$flow-designer.do?sysparm_nostack=true#');
})();

function isValidSysHubFlow(sysId) {
	var sysHubFlowGr = new GlideRecord("sys_hub_flow");
	return sysHubFlowGr.get(sysId);
}