- 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
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
09-30-2019 06:58 AM
Thank you, I was trying everything to hide it there first and it wasn't working. Appreciate the assist! Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2020 08:18 AM
Hi Ankur,
I tried the above condition on a record in Service Portal but its not quite working for me. I am on Orlando and I already have a condition to hide the ui action if record is closed which works.
Should it work with the below in the condition field?
current.state!=3&¤t.state!=4&¤t.state!=7&&gs.action.getGlideURI().getMap().get('portal') == 'true'
Regards,
Eli
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2020 08:14 AM
It would be nice if you post this as question since this is an old thread and will be difficult to track
please post your question link here
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader