Hide UI button from backend but not portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2025 12:06 AM
I have a UI button on a form which I want to hide in the backend but not in the portal. How to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2025 02:12 AM
add this and it will work
add the portal name instead of sp and add the table name instead of incident
gs.action.getGlideURI().toString().indexOf('/sp') != -1 && gs.action.getGlideURI().toString().indexOf('incident.do') == -1
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2025 07:00 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2025 01:30 AM
Hi, you need to check the current URL and determine from that if you are in the Portal or not. If you are using the default Service Portal "sp" then you can check for "/sp". But to make it more generic and re-usable I would suggest the following approach.
All backend pages look like this: page.do -> So you can check if your current URL contains the .do or not.
Here is the script:
var currentUrl = gs.action.getGlideURI().toString();
// example value for the backend: incident_list.do?sysparm_view=ess
// example value for the portal: sp?id=my_requests
var currentPage = currentUrl.split('\\?')[0];
// example value for the backend: incident_list.do
// example value for the portal: sp
if(currentPage.endsWith('.do')){
gs.info('The script was executed in the backend. Hiding the UI Action.');
} else {
gs.info('The script was executed in the portal. Showing the UI Action.');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2025 01:36 AM - edited ‎05-02-2025 01:37 AM
Thank you and where will this script go?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2025 02:12 AM
add this and it will work
add the portal name instead of sp and add the table name instead of incident
gs.action.getGlideURI().toString().indexOf('/sp') != -1 && gs.action.getGlideURI().toString().indexOf('incident.do') == -1
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader