Hide containers based on choice options

sailesh1
Tera Contributor

HI,

Is there anyway to hide the containers based on the choice option selected.

I know it would work using UI policy, but I also tried the same via Catalog client script ('on change'), which didn't help.

Can anyone of you help me out?

#Snippet I used

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    
 var num=g_form.getValue('firewall_no_of_rules');
    if(num==2)
        {
            
            g_form.setVisible('firewall_rules2',true);
        }
    else if(num==3)
        {
            g_form.setVisible('firewall_rules3',true);
        }

Thanks

Sailesh

1 ACCEPTED SOLUTION

BigMikeyVegas
Tera Guru

Did you ever find an answer for this? I am trying something similar.

 

I am using this code, and it is not working...

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) {}
   }

View solution in original post

7 REPLIES 7

Abhijeet Upadhy
Tera Expert

Hello Ssailesh

 

Inspect the element by using 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";

 

Thanks

Abhijeet Upadhyay

Hi Abhijeet,

It's helpful and working.

But could you also help me the same way on Service Portal as well.

I know that Container variables doesn't work on SP! just to know if you have any way for this.

And,

Is it possible to hide the containers on load at the first place and make visible only when the choice is selected. I think my "on change" script is not working at this point.

Hi Abhijeet,

 

This is perfect! It worked.

But it is not working on Service Portal. Do you have a solution for that.

Rajesh Mushke
Mega Sage
Mega Sage
Hey Sailesh, did you tried with g_form.setDisplay('YOUR_VARIABLE_NAME',false);} Which version currently using? if you are using Jakarta/Kingston it's not possible to hide a container if you have any mandatory variables in that container Please Refer: https://docs.servicenow.com/product/service_catalog_management/reference/r_HideCascdVarsOrerdItem.html Let me know if you need more help. Thanks, Rajashekhar Mushke Community Leader -18


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke