onChange Client Script looping through MRVS (Multi-Row Variable Set) fields

neil_b
Tera Guru

I have a record producer that currently has a variable set with an amount field and if a user tries to submit a request with amount < $10.00, then a client script is ran, and a prompt appears notifying the user that a request is not required to be submitted and it clears the amount field.

 

Within the same record producer, there is another variable set configured as a MRVS and contains a Yes/No variable 'requires_research' and if that variable is set to Yes, then the client script needs to be ignored, and the user must submit the request regardless of the amount, even if < $10.00.

 

So essentially, the condition would be:

If the amount is < $1.00 && 'requires_research' is No, notify the user with an on-screen info message and clear the amount field.

Else If 'requires_research' is Yes, no message appears, amount remains, and user must submit the request, regardless of the amount.

 

Here is my client script:

 

 

 

 

var val = 10;
var researchNeeded = '';
var multiRowVariableSet = JSON.parse(g_form.getValue('additionalinfo')); // get the MRVS name
for(var i = 0 ; i < multiRowVariableSet.length ; i ++){
if(multiRowVariableSet[i].requires_research == 'No'){ // get the variable name
		researchNeeded = 'False';
	}
	else {
		researchNeeded = 'True';
	}
}
if(g_form.getIntValue('amount')<=val && researchNeeded == 'False'){  // if the amount is < $10.00 & requires_research is No
	var answer = confirm('Based on the amount entered, you do not need to submit this request');
	if (!answer){
		g_form.clearValue('amount');
	}
	else{  // otherwise, if requires_research == Yes, user can submit the request and no confirmation prompt appears
		g_form.clearValue('amount');
	}
}

 

 

 

 

 The prompts aren't working as expected in the Service Portal when submitting the request with either of these conditions. 

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi neil_b,

 

Your 'for' loop has "

i < gr.length

 and I don't see where 'gr' is defined. Do you mean to use 'multiRowVaribleSet.length' there?

View solution in original post

4 REPLIES 4

Bert_c1
Kilo Patron

Hi neil_b,

 

Your 'for' loop has "

i < gr.length

 and I don't see where 'gr' is defined. Do you mean to use 'multiRowVaribleSet.length' there?

@Bert_c1 good catch! I will try and update that and see if it works! One second.

@Bert_c1 that was it! Thank you!

neil_b
Tera Guru

Another thing I need to mention is that onChange does not work with MRVS.

 

I discovered that I had to change this from OnChange to OnSubmit, and then the client script finally worked. 🙂