How to force / redirect a catalog item to open in Service Portal if accessed from the platform?

Lisa Silvaroli
Tera Guru

Is there a way to force a catalog item to open in the Service Portal?

9 REPLIES 9

Brad Tilton
ServiceNow Employee

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.

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?

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.

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;
    }
}