Is it possible to get Previous URL in ServiceNow?

Suresh1
Tera Guru

Hi Guys,

 

Is it possible to get previous page URL ? Basically we have a scenario. We have a table say 'problem' and have a related list as 'incident' table. So, if i click on one of related incident it goes to incident table. Here can we get that previous URL / Page belongs to problem record?

We have gs.action.getGlideURI().toString()  which will give current page URL only but cannot give previous page URL.

Let me know if this is feasible.

Thanks,
Suresh

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

You can try:

GlideSession.get().getStack().bottom();

 

This will return something like:

find_real_file.png

View solution in original post

8 REPLIES 8

Willem
Giga Sage
Giga Sage

You can try:

GlideSession.get().getStack().bottom();

 

This will return something like:

find_real_file.png

Willem
Giga Sage
Giga Sage

Hi Suresh,

Did this answer your question? If so, please mark the answer Correct. this will close the thread and lets others find the answer as well.

If not, please let us know how we can help.

Suresh1
Tera Guru

Hi All,

 

I just used a boolean field on a table and set it when i visit the page this has solved my requirement.

 

Thanks,
Suresh

Eric Medina
Tera Contributor

I created this function which will give you back the URL that is second from the top of the stack. Unfortunately, it's not 100% accurate at getting the previous page if the user is browsing ServiceNow in multiple tabs/windows at the same time but it works well enough for my use case.

function getPreviousURL() {
	var stack = GlideSession.get().getStack();
	var topOfStack = stack.pop();
	var previousURL = stack.pop();
	stack.push(previousURL);
	stack.push(topOfStack);
	return previousURL;
}