- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I need to create an onLoad catalog client script on my catalog item that will pop up a message:
"do you want to continue?"
and under will be two buttons:
"Yes" and "No"
If the user will click on 'Yes' the pop up will be closed and he will stay at the same page.
If he will click 'No' then he needs to redirect to Service Portal homepage
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Community Alums,
To achieve this, follow these steps:
- Create a Catalog Client Script on your catalog item.
- Set the Type to onLoad.
- In the script field, enter:
function onLoad() {
// Use SPModal in Service Portal
if (typeof spModal !== 'undefined') {
spModal.open({
title: "Confirmation",
message: "Do you want to continue?",
buttons: [
{ label: 'Yes', value: true, primary: true },
{ label: 'No', value: false }
]
}).then(function(response) {
if (response.value === false) {
// Redirect to Service Portal home
top.window.location = '/sp';
}
});
} else {
// Fallback for classic UI (not SP)
var answer = confirm("Do you want to continue?");
if (!answer) {
top.window.location = "home.do";
}
}
}On loading the Catalog Item on Service Portal:
When click No it redirect to Service Portal homepage:
Similarly, on loading the Catalog Item on Classic UI:
When click No it redirect to ServiceNow Platform homepage:
If my response helped, please mark it as the accepted solution so others can benefit as well.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Community Alums,
To achieve this, follow these steps:
- Create a Catalog Client Script on your catalog item.
- Set the Type to onLoad.
- In the script field, enter:
function onLoad() {
// Use SPModal in Service Portal
if (typeof spModal !== 'undefined') {
spModal.open({
title: "Confirmation",
message: "Do you want to continue?",
buttons: [
{ label: 'Yes', value: true, primary: true },
{ label: 'No', value: false }
]
}).then(function(response) {
if (response.value === false) {
// Redirect to Service Portal home
top.window.location = '/sp';
}
});
} else {
// Fallback for classic UI (not SP)
var answer = confirm("Do you want to continue?");
if (!answer) {
top.window.location = "home.do";
}
}
}On loading the Catalog Item on Service Portal:
When click No it redirect to Service Portal homepage:
Similarly, on loading the Catalog Item on Classic UI:
When click No it redirect to ServiceNow Platform homepage:
If my response helped, please mark it as the accepted solution so others can benefit as well.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Community Alums,
If this solution helped, please consider marking it as accepted solution to support the community.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
@M Iftikhar is there any way that it wont ask twice if u want to leave without saving the changes?
because after you click that you want to leave it asks again if u want to leave without saving the changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
@M Iftikhar hi but if you click No it asks again if you want to leave without the changes. is it possible that it will not asks twice?
