Open the SAC tenant home page via a script url

Open the SAC home page in the current browser tab

The easiest way to test this script is to add it in a button.
Add your tenant name & ID to the script

If you want the home page to open in a new browser tab, just change the parameter ‘false‘ to ‘true

Using a URL with dynamic Tenant & ID

This is useful if you’re transporting stories between tenants and want the home url opened to be the one the story is currently being viewed in.

var HomeURL = NavigationUtils.createApplicationUrl(Application.getInfo().id); 
NavigationUtils.openUrl(HomeURL.slice(0,HomeURL.lastIndexOf("/sap/fpa/ui/")
+12).concat("app.html#;view_id=home"),false);

Code language: JavaScript (javascript)

Script breakdown and explanation

  1. First we retrieve the current URL of the current SAC story

var HomeURL = NavigationUtils.createApplicationUrl(Application.getInfo().id);

This outputs the full URL path of the story we’re currently viewing:
https://basic-trial-sac-eu10.cfapps.eu10.hana.ondemand.com/sap/fpa/ui/tenants/b2329/bo/application/7AE09D80EE7FB1FEF34922AFF9DC3FB7?mode=present

Next, we need to split out parts of the HomeURL to generate the final link to the SAC tenant home page.
NavigationUtils.openUrl(HomeURL.slice(0,HomeURL.lastIndexOf(“/sap/fpa/ui/”)+12).concat(“app.html#;view_id=home”),false);


HomeURL.lastIndexOf(“/sap/fpa/ui/”) + 12

This part of the code finds the position where the string “/sap/fpa/ui/” appears in the HomeURL.
Why +12?
“/sap/fpa/ui/” is 12 characters long, adding 12 ensures the slice includes the entire “/sap/fpa/ui/” path.

HomeURL.slice(0, HomeURL.lastIndexOf(“/sap/fpa/ui/”) + 12)
This extracts only the part of the URL up to and including “/sap/fpa/ui/”  e.g.
https://basic-trial-sac-eu10.cfapps.eu10.hana.ondemand.com/sap/fpa/ui/

concat(“app.html#;view_id=home”)

This appends “app.html#;view_id=home” to the sliced URL, creating the final URL below:

>> https://basic-trial-sac-eu10.cfapps.eu10.hana.ondemand.com/sap/fpa/ui/app.html#/home

,false);
This final part of the script tells the browser whether to open the link in a new browser tab, or the current one.  true = new tab    false = current tab

Scroll to Top