Portal shortcut opening within frame
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2023 10:07 AM
I have a question regarding the favorite for "Self Service - Switch to Portal" when clicked from the Main App View.
How do we prevent it from opening in a new tab, but open within the same tab, with the favorites still pinned on the left?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2023 12:52 PM
Hi @VL10 ,
Hope you are doing great.
To ensure that the portal opens within the same tab while keeping the favorites pinned on the left, use UI script. A UI Script allows us to modify the behavior of the user interface elements in ServiceNow.
Reference code:
To implement this code, follow these steps:
- Create a new UI Script record
- In the "Script" field, use below code:.
function onLoad() {
// Get the 'Self Service - Switch to Portal' favorite element
var favoriteElement = document.getElementById('sys_app_sidebar_self_service_switch_to_portal');
// Add an event listener to override the default behavior
favoriteElement.addEventListener('click', function(event) {
event.preventDefault(); // Prevent the default action of opening in a new tab
window.location.href = '/sp'; // Replace '/sp' with the correct URL of your portal if different
// Optionally, you can update the favorite's active state to reflect the change
favoriteElement.classList.add('active'); // Add the 'active' class to highlight the favorite
// You may need to refresh the left navigation pane to ensure the changes are reflected
// Add the following line if necessary:
// top.gsftNav.refreshNavigator();
});
}
- Save the UI Script record.
- Navigate to the "Main App View" or the corresponding UI page where the favorite is located.
- Edit the UI page and add the UI Script record you created in the previous step to the "Client Scripts" related list.
- Save the UI page changes.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2023 09:32 PM
Thank you for your reply. While this may work I don't think code is required.
Standard bookmark users: https://INSTANCE.service-now.com/itsm?sysparm_stack=no
However using this will allow it to open within the frame:
https://INSTANCE.service-now.com/now/nav/ui/classic/params/target/itsm%3Fsysparm_stack%3Dno
Perhaps we can edit the link within the bookmark table to do the job?