Not able to hide the variable set of a catalog item

aditya174
Tera Guru

Hi Im trying to hide my variable set Create new group based on the selection of the request type:

aditya174_0-1731424202916.pngaditya174_1-1731424218209.png

Using the following code:

aditya174_2-1731424244430.png

 

function onChange(control, oldValue, newValue, isLoading) {
//    if (isLoading || newValue == '') {
//       return;
//    }
   var type = g_form.getValue('request_type');
   if(type=='create'){
	//g_form.addInfoMessage('test '+type);
	g_form.setVisible('Create_New_Group',false);
	g_form.setDisplay('Create_New_Group',false);
	
	g_form.setVisible('create_new_group',false);
	g_form.setDisplay('create_new_group',false);
   }

   //Type appropriate comment here, and begin script below
   
}

 

But it is no hiding the variable set, I've also checked there are no containers in the variable set.

2 REPLIES 2

Pradeep Thipani
Mega Sage

Hi @aditya174 ,

 

I have answered this question under https://www.servicenow.com/community/developer-forum/not-able-to-hide-the-variable-set-of-a-catalog-...

Let me know that is working as expected.

 

Thanks,

pradeep[ 

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep

Juhi Poddar
Kilo Patron

Hello @aditya174 

I have found the mistake, replace variable set name with the variable name. You need to mention each variable that has to be variable set to false.

g_form.setDisplay('Create_New_Group',false); //replace variable set name with variable name in variable set

replace with:

g_form.setDisplay('group_name',false); //group_name is the variable name in variable set

 Here are the screenshots from my PDI:

Catalog Client script:

JuhiPoddar_4-1731432811490.png

Updated script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    var type = g_form.getValue('request_type');
    if (type == 'create') { 
        g_form.setVisible('group1', false);//group1 is the variable name in variable set
		//similarly add other variables
    } else {
        g_form.setVisible('group1', true); //To show back the variable when type is not 'create'
		//similarly add other variables
    }
}

Variable in variable set:

JuhiPoddar_2-1731432271888.png

Result:

when request type is not create

JuhiPoddar_5-1731432854335.png

when request type is create

JuhiPoddar_6-1731432871355.png

Note: type == 'create', here 'create' is the value assign to the choice Create

JuhiPoddar_7-1731433121491.png

"If you found my answer helpful, please like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

Thank You
Juhi Poddar