- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019 06:32 AM
Hi All,
I have a need to hide a UI Action on a form if the user is coming form the Service Portal. Easy enough to do I thought, I would add a new parameter to my link that indicates "portal=true" I pull the value out of the URL and if it's true, I am hiding the UI Action. I am doing this all through an on load client script. It works great for the upper form button, but I still see the button in the lower section of the form. This is odd, when I inspect the page the buttons both have the same id, why would one be hiding and the other not?
Here is the client script:
function onLoad() {
//Hide the return to portal button
$('portal_return').hide();
//Get the "portal" value from the URL
var sPortal = getParmVal('portal');
//IF they are coming from the portal, portal=true, then show the return to portal button.
if(sPortal=='true' && !g_form.isNewRecord()){
$('portal_return').show();
changeButtonColor('portal_return', '#8bc34a');
}
}
//Function to part the URL and get the parameter 'portal' which indicates whether they are coming from the portal.
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}
//manipulate the color of the button
function changeButtonColor(buttonID, backgroundColor) {
try{
//Find the button(s) by ID and change the background color
$$('button[id=' + buttonID + ']').each(function(elmt) {
elmt.style.backgroundColor = backgroundColor;
elmt.style.color = '#ffffff'; //make the button text white
});
}catch(e){}
}
Not sure what is going on here and why it doesn't hide from the lower section of the form but hides fine from the upper section. Am I just over complicating this?
Any help is greatly appreciated. Thank you in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019 06:47 AM
Hi,
It would hide the 1st html element with that id although you are iterating I believe
why not hide that UI action using UI action condition instead of onload client script?
put this in the UI action condition
gs.action.getGlideURI().getMap().get('portal') == 'true' && !current.isNewRecord()
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
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-28-2020 06:12 AM
Hi Ankur,
Done please check:
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019 06:49 AM
Those are actually 2 different buttons. I think in a recent release something was added so that the id of the bottom button would be action_name_bottom, so in your case, portal_return_bottom. You would need a second line to show and hide that bottom button.
That being said, I think Ankur has the right answer to hide it server side in the condition if possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019 06:57 AM
Hi Brad,
Yes, I have NY in my DEV environment and can hide it successfully by appending the '_bottom' to the button name, the instance I am having trouble with is London. Ankur solved it for me, but thank you.
Jim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019 07:05 AM
Just for future reference, the issue is that in your London instance the buttons have the same id, and when you reference by id in the way that you did to show and hide the button, it only finds the first one. You're actually already solving for that problem in the changeButtonColor function where you're iterating through both buttons and changing the color.