Loop through a variable in MRVS to check the condition

Karan31
Tera Contributor

I have a variable in a form within multi row variable set.

The variable is a YES/NO field. I wanted to check for every row added the if at any row "no" is selected on the variable the form should not be submitted

16 REPLIES 16

AbhishekGardade
Giga Sage

Hello Karan

Can you specify where are you facing issue? How much of code is completed?

This article may help you:

Accessing Multi-Row Variable Set value

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
ServiceNow MVP 2020

Thank you,
Abhishek Gardade

@Abhishek Gardade i don't know if it is achievable don't have much experience with MRVS

Harsh Vardhan
Giga Patron

yes you can do that.

 

Here we go. 

 

Sample Code: 

 

function onSubmit() {

	var gr = JSON.parse(g_form.getValue('apps_enable'));


	for(var i = 0 ; i < gr.length ; i ++){


		if(gr[i].set == 'No' ||  gr[i].set1 =='No'){
			alert(' the column contains No ');
			return false;
		}


	}



}

 

Note: apps_enable is the internal name of your MRVS .

screenshot for reference. 

 

find_real_file.png

 

Note: I tested it and working fine. 

 

If my answer helped you, mark it as correct and  helpful.

Hi Harshvardhan , will this script apply to variable set or item?