Home
Analytics
TypeError: Cannot find default value for object (beforeOpen)
ArK
<p>Hi,</p>
<p> </p>
<p>I have a scripted data set where I use a REST API to get JSON data which is inserted into the data set.</p>
<p> </p>
<p>I have a parameter where the user picks a week (using jQuery date picker) and the dates are parsed in a beforeOpen script and later passed on to the URL in the open scrip. The parameter has a default value consistent with the values the user can pick.</p>
<p> </p>
<p>This works great when the API returns a JSON object with data in it, but I get an exception when the JSON is an empty object. The weird thing is that the exception originates from the beforeOpen script but shouldn't this phase be ignorant of the actual data the data set will be receiving? If the exception occurs in beforeOpen then shouldn't it occur every time (even when there is data in the JSON)?</p>
<p> </p>
<p>Any idea what's going on here?</p>
<p> </p>
<p>Thanks,</p>
<p>Arto</p>
Find more posts tagged with
Comments
Clement Wong
<p>What does your code look like? Is there any defensive coding in there?</p>
<p> </p>
<p>Attached is a sample using a REST JSON. Setting the parameter (checked) will return no results. We check in the beforeOpen event to verify if the JSON data member is null or contains data.</p>
<p> </p>
<p> </p>
<p><strong>beforeOpen </strong>(where we check to see if our result is available or not)</p>
<pre class="_prettyXprint">
json = JSON.parse(result);
//logger.warning (result);
//logger.warning (json);
if (json.Localities === undefined) {
theLimit = 0;
}
else {
theLimit = json.Localities.length;
}
</pre>
<p><strong>fetch</strong></p>
<pre class="_prettyXprint">
if (recNum >= theLimit) {
return false;
}
else {
row["LocalityName"] = json.Localities[recNum].Locality.LocalityName;
row["LocalityCode"] = json.Localities[recNum].Locality.LocalityCode;
recNum++;
return true;
}
</pre>
<p><span style="color:#b22222;"><em>If you are using BIRT 4.5.0+, it has built-in JSON support so you <strong>do not</strong> need the helper JavaScript file, "json.js", in the root of your project folder.</em></span></p>
<p> </p>
<p><span style="color:#b22222;"><em>The difference between the two designs in the ZIP is that the one for pre-BIRT 4.5.0, there is an external Resources reference to "json.js", and the one for 4.5.0 does not have it.</em></span></p>
<p> </p>
<p><span style="color:#b22222;"><em>If you don't have it in pre-BIRT 4.5.0, when attempting to run the report, you will see an error like ... <strong>ReferenceError: "JSON" is not defined.</strong></em></span></p>
<p> </p>