window.location.href alternative script for scoped app

MaharshiC
Tera Contributor

Hi,

 

I have created a related list action in scoped app and is using the folowing code but window.location.href is not working. Can somebody give me the alternative code that I can use here?

function onClick() {
alert('This is a simple alert message!');
var a = window.location.href;
alert('newThis is a simple alert message!');
alert('abc'+a);
1 ACCEPTED SOLUTION

Ramya Neelam1
Tera Guru

Hi MaharshiC,

 

You can try with this 'top.location.href'.

 

Thanks

Ramya.N

View solution in original post

8 REPLIES 8

Sandeep Rajput
Tera Patron
Tera Patron

@MaharshiC Unfortunately, window.location.href is not available in the scoped application client script/UI action and there is simply no way to access it.

Hi @Sandeep Rajput ,

Thanks for your reply. Can you give me the alternative code that I can use to get the current URL?

@MaharshiC You can create a UI Script in the Global scope and call that UI Script from your scoped client script to fetch the window object. However, I will not recommend this as if your scoped app is meant to be distributed on the ServiceNow app store then the UI Script in the Global scope can't be packaged with it. 

Hi @Sandeep Rajput ,

 

So what will be your suggestion then ? Any other alternative than to create the UI script in global scope?