Multi Row Variable Set - Dynamic Select Box

Alex Ward
Tera Expert

Has anyone had any experience in adding options to a select box within a multi-row variable set, based on information added to another multi-row variable set?

e.g.

MRVS1 has two fields, Type (pre-filled select box) and Name (string).

MRVS2 has one field, Name (empty select box).

Based on the Type selected in MRVS1 the Name gets added as an option for Name in MRVS2

 

I'm thinking that g_form.addOption may be a possibility. But I'm unsure how I can access the value of Name in MRVS1 each time a new line is added

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Unfortunately you cannot influence variables within the MRVS from outside the multi row variable set. So in short: just not possible.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Did this solve your question? Or do we need to follow-up on this?

Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Did this solve your question? Or do we need to follow-up on this?

Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

 

Your advice did help in as much as it confirmed that it would not be posible to approach the issue in the manner I had planned.

This prompted me to think about the solution in another way, here is what I came up with.....

 

I introduced a check box "Generate Options" and an onChange Catalog Client Script. The Catalog Client Script gets the values from MRVS1 and places the required Key:Value pairing into MRVS2.

Please excuse any best practice breaches etc, this is a working solution, but i am aware it could prehaps be better:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

        if (newValue == 'true') {
	
	        var obj = JSON.parse(g_form.getValue('mrvs_1')); //get values from MRVS1
	        var nObj = []; //blank array
	
	        for (var i=0; i < obj.length; i++) { //iterate through obj
                var ft = obj[i].field_type; //get value of field_type at position i
		        var name = obj[i].name; //get value of name at position i
		        var noo = obj[i].number_of_options; //get value of number_of_options at position i
		
		        if (ft == 'check-box' || ft == 'drop-down') { //check the field_type
			        for (var i2=0; i2 < noo; i2++) { //repeat for the number of options required
				        nObj.push({
					        field_name: name //push field_name into an array
				        });
				        g_form.setValue('mrvs_2', JSON.stringify(nObj)); //set the values in MRVS2
			        }
		        }
	        }
	}
}

Please feel free to make any suggestions that may improve the above code. All any any suggestions welcome.