how to hide variables in a multi-row variable set ?

rohit2926
Kilo Contributor

I need to show and hide variables based on choice list options selected in a mmulti-row variable set, can anyone suggest any altrnate for this as Servicenow has made the UI Policy action option "Visible" locked out for Multi-row variable set, nor is the g_form.setDisplay('field_name', false);  working on this type of variable set.

 find_real_file.png

11 REPLIES 11

Can you provide the script you used to copy the first MRVS to the second one?

You can write the on-submit client script to copy from  one MVRS to other like below.

 

 

1) Get the values from MRVS1 and convert it as array to process easily

    var mvrs1_array ='';
    var multirow_variableset_rows=g_form.getValue('mrvs1');

           if(multirow_variableset_rows !='[]'){
                     mvrs1_array=JSON.parse(multirow_variableset_rows);
                             }

2) Now we have to create an array of object which have the fields of MVRS2

              var object ={};
              var mvrs2_array=[];

              for( i=0;mvrs1_array.length>i;i++){

                  object ={};
                     object.var1= mvrs1_array[i].var1;
                     object.var2= mvrs1_array[i].var2;
                     object.var3= mvrs1_array[i].var3;
                     object.var4= '';
                     object.var5= '';
                      mvrs2_array.push(object);

                                     }


3) Now convert the array into JSON object and set the variable 2 value

                    var mvrs2_json=JSON.stringify(mvrs2_array);
                    g_form.setValue('mrvs2',mvrs2_json);

 

Hope it will be helpful 🙂

Ajay_Chavan
Kilo Sage

You can achieve this using DOM

 

i have hide it refer below SS:

 

Refer below code:

function onLoad() {
   //Type appropriate comment here, and begin script below
	
	//table: id="31a5d7f71b6440109998da49cc4bcbca_table"
	var tbl = document.getElementById("31a5d7f71b6440109998da49cc4bcbca");
var col = tbl.getElementsByTagName('th')[2].style.visibility="hidden";

	
   
}

 

this is a catalog onLoad client script

 

incase you need any help writing script let me know

 

If this resolves your query, please mark my comments as correct and helpful  .

Regards,

Ajay Chavan

My Community Articles

LinkedIn

 

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Hi Ajay,

 

I tried to reproduce this using the element ID using the browser console, but no other changes.  It didn't seem to work for me. 

 

Here's where I got the table ID:

find_real_file.png

 

Here's the script as I tried it:

function onLoad() {

   //Hide Multi Row Variable - this uses DOM manip, but is currently the only known way to conditionally hide a Multi Row Variable from a Catalog Item or Record Producer
	
	//table: id="e4b8ae051b0898142457dac2cd4bcbcd_table"
	var tbl = document.getElementById("e4b8ae051b0898142457dac2cd4bcbcd");
var col = tbl.getElementsByTagName('th')[2].style.visibility="hidden";

	  
}

 

What am I doing wrong?  Am I using the wrong element ID? 

 

Thanks,

Robert

LOL Nevermind.  Conditionally hiding a multi row variable set with a Catalog UI Policy was actually pretty straightforward. No need for DOM manip. SN discourages that anyhow.

 

Maybe it was updated in New York...

 

Regards,

Robert