- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 11:46 AM
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?
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.");
}
}
'
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 12:38 PM
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);
MVP 2025 ✨
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 01:07 PM
These logs should be displayed on the screen, not on the console... If you just want to know the value of your 'my_managed_assets' field, is anything displayed? We need to make sure that this field has value to parse it.
var mrvsValue = g_form.getValue('my_managed_assets');
g_form.addInfoMessage(mrvsValue);
MVP 2025 ✨
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 01:11 PM
I'm dumb. The client script wasn't active when I was testing your suggestions, but your idea about splitting the variable up fixed it!
This is the script I used:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var mrvsValue = g_form.getValue('my_managed_assets');
if (mrvsValue != "") {
var MRVS = JSON.parse(mrvsValue);
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.");
}
}
}
