Hide UI button from backend but not portal

vidhya_mouli
Giga Sage

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?

10 REPLIES 10

@vidhya_mouli 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@vidhya_mouli 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Paul Kunze
Tera Guru

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.');
}

 

Thank you and where will this script go?

@vidhya_mouli 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader