message shouldnt come in cab workbench
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
I wan to restrict message in cab workbench page , however i am not getting message anywhere not in classic UI not in SOW not in cab workbench , however i need message in classic UI and in SOW .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
The reason your script isn't working is that window.location is generally blocked or unreliable in modern Workspaces and the CAB Workbench due to security "sandboxing."
To achieve this, you should use the g_form.getControl() or the glide.ui.can_debug_ajax approach, but the most reliable way in ServiceNow is to check the User Experience context.
Try replacing your URL logic with this:
JavaScript
function onLoad() {
// Check if we are in the CAB Workbench by checking the URL or a specific element
var isCAB = window.top.location.href.includes('cab_workbench');
if (isCAB) {
return;
}
var state = g_form.getValue("state");
if (state === "-5" || g_form.isNewRecord()) {
g_form.addInfoMessage("Hi");
}
}
A few tips to ensure it works across all UIs:
UI Type: Make sure the Client Script "UI Type" is set to All. If it's set to "Desktop," it won't run in SOW or the Workbench.
Isolate Script: Ensure the "Isolate script" checkbox on the Client Script record is unchecked. This allows the script to access the window object, though keep in mind this is not best practice for long-term upgrades.
Alternative: If you want a "cleaner" way without using window, check for a specific field or element that only exists in the Workbench view, or use a View-specific Client Script if you have a dedicated CAB view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The message in SOW is appearing but its going of in 4 seconds is there any other way that we can keep that message for some time until the user click on cross , like how addinfo message in native UI appears.
