How to force / redirect a catalog item to open in Service Portal if accessed from the platform?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 06:18 AM
Is there a way to force a catalog item to open in the Service Portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 06:36 AM
Do you want to do this for all catalog items or just a specific one, and for all users or just ess?
You could use an onload client script that checks the url and redirects the user. With that method you could be targeted in the items and users you target.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 06:43 AM
Just for one catalog item (for now) and any user who access it.
Do you have an example of the script I could achieve this with?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 06:53 AM
You can add an onload client script to that catalog item. If you set the type to Desktop, then it will only run on the platform view so you won't need to check the url:
function onLoad() {
var spItemLink = 'https://instance.service-now.com/sp?id=sc_cat_item&sys_id=';
var itemSysID = g_form.getUniqueValue;
top.window.location = spItemLink + itemSysID;
}
You would need to replace instance with your instance name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2025 09:50 AM
That was very helpful. But I think you forgot a () after g_form.getUniqueValue. Also I think it is better to check if the user is already on the /sp and only redirect if not there. And since we have dev/uat/prod URLs you can do a regex:
function onLoad() {
var url = top.window.location.href;
var instance = url.match(/https\W{3}\w+\.service-now.com/);
if (!(url.includes('service-now.com/sp')) {
var spItemLink = instance + '/sp?id=sc_cat_item&sys_id=';
var itemSysID = g_form.getUniqueValue();
top.window.location = spItemLink + itemSysID;
}
}
