How to get the full URL when it has already been encoded in a ServiceNow client script?

Nguyen Van Au
Tera Contributor

Is there any way to get the ServiceNow URL in a client script? I tried: sysparmQuery = g_form.getParameter('sysparm_query'); But it didn’t work as expected. Is there another way to get the value of `classification` from the URL? For example, the URL:

1.

https://dev123408.service-now.com/now/nav/ui/classic/params/target/_to_do_comment.do%3Fsys_id%3D-1%2...

2. https://dev123408.service-now.com/_to_do_comment.do?sysparm_query=_computer_information%3D__ENC__ZjZ...
I need to get the value of `classification`.
please help me,

1 ACCEPTED SOLUTION

@Nguyen Van Au 

did you print what came in alert using this?

alert(top.location.href);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

J Siva
Tera Sage

Hi @Nguyen Van Au 
Try the below cript..

function onLoad() {

    var url = new GlideURL(window.location.href);
    var urlParam = url.getParam('classification');
    g_form.addInfoMessage('Value of classification: ' + urlParam);
}

Regards,
Siva

I have used window.location.href and top.location.href but still haven’t been successful.
My situation is that the client script is written and runs on a new form.
For example, from List A, I click a button that sets the URL, then go to Form B, which is the form I am working on.
I need to get the URL value that is returned.
However, it seems that using window.location.href and top.location.href does not work.
Is there any other way to get my current URL?

Ankur Bawiskar
Tera Patron
Tera Patron

@Nguyen Van Au 

you are writing client script on which table?

are you redirecting user from somewhere to this URL and then want to write onLoad to get that value?

try this to grab the value in client script

function onLoad() {
    var gUrl = new GlideURL();
    gUrl.setFromCurrent();
    var classification = gUrl.getParam("classification");
    alert(classification);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Yes, this is a client script that will run on that exact URL.
By setting the URL beforehand and then clicking a UI Action, I navigate to the form I am working on.
I need to get the classification value in order to show or hide the “Buy” button.
Unfortunately, I have tried and it did not work.