How to Show/hide the choice of MRVS variable based on another MRVS variable on the form.

shaik11
Tera Expert

Hi All,

I have different MRVS in the catalog form.

First MRVS consists of reference variable.

Second MRVS consists of select Box variable with 4 choices

My task is based on the first MRVS reference variable data, I need to add/Remove the choices in second MRVS variable.

It needs to applicable for both Catalog Item and as well as to Portal, how to achieve this by using client script /Scriptinclude ?

Please provide code inputs.

Thank You,

Reshma.

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Reshma,

You can do this with an onLoad Catalog Client Script that applies to the second MRVS on the catalog item view

BradBowman_0-1666785545891.png

In this example, the internal name of the first MRVS is mrvs1, which contains a reference variable named v_user, and the select box variable in the second MRVS is named v_choice with the choice values choice_1, choice_2, etc., and if any of the rows of MRVS1 contain a certain user selected in the reference, then the third Choice value will be removed from MRVS2. 

function onLoad() {
	var mrvs1 = g_service_catalog.parent.getValue('mrvs1'); //MRVS internal name
	if(mrvs1.length > 2){//native UI returns [] for empty MRVS value which causes a JSON error
		var obj = JSON.parse(mrvs1);
		for (var i=0; i<obj.length; i++) {
			if (obj[i].v_user == '62826bf03710200044e0bfc8bcbe5df1') { 
				g_form.removeOption('v_choice', 'choice_3');
			}
		}
	}
}

 

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Hi Reshma,

You can do this with an onLoad Catalog Client Script that applies to the second MRVS on the catalog item view

BradBowman_0-1666785545891.png

In this example, the internal name of the first MRVS is mrvs1, which contains a reference variable named v_user, and the select box variable in the second MRVS is named v_choice with the choice values choice_1, choice_2, etc., and if any of the rows of MRVS1 contain a certain user selected in the reference, then the third Choice value will be removed from MRVS2. 

function onLoad() {
	var mrvs1 = g_service_catalog.parent.getValue('mrvs1'); //MRVS internal name
	if(mrvs1.length > 2){//native UI returns [] for empty MRVS value which causes a JSON error
		var obj = JSON.parse(mrvs1);
		for (var i=0; i<obj.length; i++) {
			if (obj[i].v_user == '62826bf03710200044e0bfc8bcbe5df1') { 
				g_form.removeOption('v_choice', 'choice_3');
			}
		}
	}
}

 

Thank you, Brad.

The above code is working fine when I compare the sys_id for each record.

My requirement is in reference variable we have multiple records, In that I need to remove Option in MRVS only for 10 records not for all.

Rather than that 10 records the option which we removed should be added.

Here, my doubt is how we compare only those 10 records (sys_Id's with that value ) .

 

Regards,

Reshma. 

You can list each of the 10 sys_ids that should cause option(s) to be removed.  If any of the rows contains one of these, the option(s) won't be able in the second MRVS.  This is what it looks like with 2

if (obj[i].v_user == '62826bf03710200044e0bfc8bcbe5df1' || obj[i].v_user == '123456789010200044e0bf1234567890' ) { 
    g_form.removeOption('v_choice', 'choice_3');
}

 

Without using sys_id's in the 'if' condition, how we can perform task.