Getting "SyntaxError: Unexpected end of JSON input" on MRVS Client Script

Winston
Tera Guru

Hello everyone, 

I'm getting SyntaxError: Unexpected end of JSON input on the below client script. I'm filtering the asset MRVS by multiple locations, and trying to a tell the user they can't add more than 50 records to the MRVS. The onScript works okay but gives me that error when the first location is added. I'm guessing because when the location is added the MRVS doesn't have anything filled in so it's throwing up that error.

Is there anyway around this?

 

find_real_file.png

 

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

	var MRVS = JSON.parse(g_form.getValue('my_managed_assets'));
	var MRVSlength = MRVS.length;
	
	if (MRVSlength > 5) {
		g_form.addErrorMessage("You can not submit more than 50 assets with this form. Please remove a filter location or assets.");
		}	
	}

'

1 ACCEPTED SOLUTION

If you get the value first and then do the parse, does it make a difference?

var mrvsValue = g_form.getValue('my_managed_assets');
var MRVS = JSON.parse(mrvsValue);	
g_form.addInfoMessage(MRVS);

var MRVSlength = MRVS.length;
g_form.addInfoMessage(MMRVSlength);

 

If you run the code below, what is displayed?

var mrvsValue = g_form.getValue('my_managed_assets');
var MRVS = JSON.stringify(mrvsValue);	
g_form.addInfoMessage(MRVS);

//var MRVSlength = MRVS.length;
//g_form.addInfoMessage(MMRVSlength);

Best regards,

Isaac Vicentini
MVP 2025


If my answer was helpful, mark it as Helpful or Accept as Solution.

View solution in original post

6 REPLIES 6

Isaac Vicentini
Mega Sage
Mega Sage

If you write a g_form.addInfoMessage(MRVS) log what is displayed?


Best regards,

Isaac Vicentini
MVP 2025


If my answer was helpful, mark it as Helpful or Accept as Solution.

This is what it's showing:

find_real_file.png

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

	var MRVS = JSON.parse(g_form.getValue('my_managed_assets'));
	var MRVSlength = MRVS.length;
	
	g_form.addInfoMessage(MRVS);
	
	/*
	if (MRVSlength > 5) {
		g_form.addErrorMessage("You can not submit more than 50 assets with this form. Please remove a filter location or assets.");
		}	
	}
	*/
}

If you get the value first and then do the parse, does it make a difference?

var mrvsValue = g_form.getValue('my_managed_assets');
var MRVS = JSON.parse(mrvsValue);	
g_form.addInfoMessage(MRVS);

var MRVSlength = MRVS.length;
g_form.addInfoMessage(MMRVSlength);

 

If you run the code below, what is displayed?

var mrvsValue = g_form.getValue('my_managed_assets');
var MRVS = JSON.stringify(mrvsValue);	
g_form.addInfoMessage(MRVS);

//var MRVSlength = MRVS.length;
//g_form.addInfoMessage(MMRVSlength);

Best regards,

Isaac Vicentini
MVP 2025


If my answer was helpful, mark it as Helpful or Accept as Solution.

I'm not seeing any errors on either one, but also no info logs that I can see