The CreatorCon Call for Content is officially open! Get started here.

Hide UI Action based on URL Parameter

jimnicholson
Giga Guru

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!

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

Thank you, I was trying everything to hide it there first and it wasn't working.  Appreciate the assist!  Thank you. 

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&&current.state!=4&&current.state!=7&&gs.action.getGlideURI().getMap().get('portal') == 'true'

 

Regards,

Eli

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

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