Hide container in portal based on user record

David Sloan
Giga Guru

I have a user-defined field on the sys_user table. Based on this field I would like to show/hide containers on the home page of our portal. As I understand it, you cannot OOB hide a container based on user criteria, so what is the best way to do this? Should I add a script to that portal page that checks this value and shows/hides the DOM element accordingly? As I understand it, this method is not advised. So what is advised? And if I am creating a script on the page, how do I check that value from the server?

10 REPLIES 10

David Sloan
Giga Guru

Still in need of help here. Again, the user criteria plug-in does not allow you to hide a container. I assume I am going to have to script something. What is the best practice for this, and how do I access the user-defined field on the sys_user table to know which containers to show/hide?

David Sloan
Giga Guru

I am going to use DOM manipulation to hide the container. I was trying to avoid that, but I have not yet found a better way.

Swapnil Soni1
Giga Guru

Hey David,

Inspect the element by using the browser's developer options and get the 'id' attribute of the container. And then use the following JavaScript code to hide/show the container.

 

Code: document.getElementById("inspected id comes here").style.display = "none";

          document.getElementById("inspected id comes here").style.display = "block";

 

 

Or you can use this script-

function onLoad() {

	var Type = g_form.getValue('variables.BI_ReqType');

   alert(Type);

         if (Type !== 'Modify Report Distribution')
                try {
                      $("container_31646219dbf317405b9add0b5e9619bc").hide();
                  } catch(error) {}
	
         if (Type !== 'Create Report')
                try {
                      $("container_12f46a19dbf317405b9add0b5e96191e").hide();					   
                   } catch(error) {}
 
         if (Type !== 'Modify Report')
               try {
                       $("container_1a53aa95dbf317405b9add0b5e9619a1").hide();
                   } catch(error) {}
 
         if (Type !== 'Schedule Report')
               try {
                      $("container_fb46ee19dbf317405b9add0b5e96198d").hide();
                   } catch(error) {}
 
         if (Type !== 'Publish Report')
                try {
                       $("container_08196e99dbf317405b9add0b5e961982").hide();			   
				   } catch(error) {}

         if (Type !== 'New Data Request')
                  try {
                       $("container_5d41fe11db3717405b9add0b5e961951").hide();
                   } catch(error) {}

         if (Type !== 'Data/Report Question')
                  try {
                       $("container_0c42b611db3717405b9add0b5e96197d").hide();
                  } catch(error) {}
   }
 

I put similar code in a JS Include for the theme, but it is not working yet. To clarify: this is the home page of the portal where I want to show/hide containers. I want to do this based on a user-defined field in the user table. I haven't even gotten to the point yet of passing that information from the user table. Right now I am just trying to see if I can change the display setting of container elements, but so far no luck.

It appears that the containers do not have ids. I thought I could hide them by assigning them a class and using jquery to hide that class, but that doesn't work.