- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 02:16 AM
I want to redirect the user in a Service Portal Widget to either:
1. The previous page in the Service Portal
2. Or the category page
after adding a sc item to the cart. I've been able to do it by hard-coding the instance name in the client script, but that means we would need to have 3 separate lines of code (one per dev, test and prod instance)
$window.location.href = "https://[instancename]/sp?id=sc_home"; // Redirect to Category page
How can I write this so that it takes the current instance url instead of hard-coding the url?
I have tried by doing the following but the user doesn't get redirected:
var url = gs.getProperty('glide.servlet.uri')
$window.location.href = url + "/sp?id=sc_home"; // Redirect to Category page
I have also tried to redirect to the previous page but I didn't manage to, therefor directing the user to the Category page instead.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 02:34 AM
Hello,
I don't think we can use gs.getPropery in client script of a widget.
I have tried the following in the client script of the widget and it seems to work (redirect to the catalog home page)
var hosturl = 'https://' + $window.location.host;
$window.location.href = hosturl + "/sp?id=sc_home";
Hope this helps!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 02:22 AM
Hi there,
If I do a gs.info, it gives me:
https://dev*****.service-now.com/
Looking at your code, you are adding:
/sp?id=sc_home
So a double slash I guess? Maybe that's already the issue.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 02:54 AM
Apparently gs.getPropery doesn't work in a SP widget but
'https://' + $window.location.host;
worked as rad suggested in this post
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 02:34 AM
Hello,
I don't think we can use gs.getPropery in client script of a widget.
I have tried the following in the client script of the widget and it seems to work (redirect to the catalog home page)
var hosturl = 'https://' + $window.location.host;
$window.location.href = hosturl + "/sp?id=sc_home";
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 02:38 AM
This did help! Thanks a bunch!