The CreatorCon Call for Content is officially open! Get started here.

How to get URL of current page in service portal

k_jayanth
Tera Contributor

I need to fetch the URL, when i select an item from the category.

function onload()

{

var href = window.location.href;

  alert('href       ' + href);

var what = getTopWindow().location.toString();

  alert('TW       ' + what);

}

These alerts works for catalog items but does not display when i load the item on service portal.

Thanks and Regards

Jayanth

1 ACCEPTED SOLUTION

parameswar
ServiceNow Employee
ServiceNow Employee

Hi,


If you don't find window object then try using 'this' object.



example:


this.location.href


View solution in original post

7 REPLIES 7

philengles
Giga Expert

Hi Jayanth,


    var currentUrl = window.location.href


    alert(currentUrl);



Above code has worked before for me. However I really would suggest that you use $sp.getParameter('your_parameter'); in your widget. It is a lot cleaner however I might be suggesting this method without really understanding your problem. If you are attempting to pass information between your "url"/backend to the widget this method should be utilized. There are a lot of Out of Box widgets taking advantage of that method if you need more assistance please let me know and I will be happy to help.


Best Regards,


  Philip Engles


  philip.engles@techport13.com


find_real_file.png


HV1
Mega Guru

Reference: documentation/widget_server_script_apis.md at 4d87f23bf877e43d740d14858116a6fa4cfb19f9 · service-po...



1. Server Side - You can use:


getMenuHREF(GlideRecord): StringReturns the (?id=) portion of the URL based on the sp_menu type.


2. Client Side - Though I have never tried it out, but in the example for $sp.getCatalogItem(), you will see servicenow using "spUtil.getURL('sc_cat_item')".


documentation/widget_server_script_apis.md at 4d87f23bf877e43d740d14858116a6fa4cfb19f9 · service-po...



Hope this helps.


- Hardik Vora


parameswar
ServiceNow Employee
ServiceNow Employee

Hi,


If you don't find window object then try using 'this' object.



example:


this.location.href


Did this actually work in service portal?



EDIT: Holy Helena, it does! I've been searching for a documented work-around for URL access for _ever_. Is this not documented anywhere, or have I just blatantly missed it?