window.location.href not working in scope application

vai
Kilo Contributor

I want to get current url of the browser in my application, but I see that window.location.href is not working in scope application.. I tried it in both my application scope and global scope catalog items, its working fine in global scope but in my application scope it is not working.

var url = window.location.href;

alert(url);

do we have any alternative for fetching url which works ni scope applications ?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vineeth,



window object doesn't work in scoped app. Here is an alternative.


1) Create ui script in global scope and have function in that which will return window.location


2) call this ui script function from your client side in your scoped app.



It should work



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

View solution in original post

7 REPLIES 7

Hi Midhun,



ServiceNow has stopped few things in scoped app such as window html object, DOM manipulation etc.


Scoped Applications and Client Scripts: A Primer



Regards


Ankur


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

The SN Nerd
Giga Sage
Giga Sage

Just remember, if your app is dependent on a custom globally scoped object


  • It won't be part of your app
  • Will need to be created in another update set
  • Your app can't be certified

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Chandu Telu
Tera Guru
Tera Guru

Hi Vineeth,




Please find the below link



Re: Scoped Application: How to open URLs in a new tab/window?



PS: Hit like, Helpful or Correct depending on the impact of the response




Thanks


Chandu Telu