Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
BIRT designer beforeOpen() not resolving function in external javascript file for a dataset
wtfacoconut
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">Environment:</p>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">- BIRT Designer v4.3.2</p>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">Problem: I have a dataset that runs a query to retrieve data from a SQL DB and I'm trying to execute a javascript function that exists in an external js file. When trying to view the "Output Columns" for that dataset I get the following error:</p>
<pre class="_prettyXprint">
org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_beforeOpen(). Source:
" + util.evaluateQueryTextExpressions(this); + "
A BIRT exception occurred. See next exception for more information.
ReferenceError: "util" is not defined. (<inline>#1)</pre>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">The javascript file which contains the function has been added to the report as a resource.</p>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">NOTE: When I actually generate the report, everything works fine as intended. However it's only in BIRT designer whenever I try to view "Output Columns" or "Preview Results" do I encounter this problem.</p>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">Assistance with resolving this problem will be greatly appreciated.</p>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">Thanks!</p>
Find more posts tagged with
Comments
JFreeman
<p>I have tried reproducing this with an external javascript file I use for logging purposes. When I call it from the beforeOpen of a data set it works properly when viewing output columns and previewing results as well as running the report.</p>
<p> </p>
<p>Can you provide a sample report and javascript file that replicates the behavior you are seeing?</p>
shivkumar150
<p>Hi JFreeman,</p>
<p> </p>
<p>I have tried a simple report wherein I need to get values from the XML Files/books.xml. When tried to view the report I'm getting an error as below:</p>
<p> </p>
<p><span><span>org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "var xhttp = new XMLHttpRequest();":<br>
Fail to execute script in function __bm_OPEN(). Source:<br>
<br>
" + var xhttp = new XMLHttpRequest(); + "<br>
<br>
A BIRT exception occurred. See next exception for more information.<br>
ReferenceError: "XMLHttpRequest" is not defined.</span></span></p>
<pre class="_prettyXprint _lang-xml _linenums:1">
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.23" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 4.5.0.v201506092134 Build <
@BUILD@>
;</property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<script-data-source name="ScriptedDataSource" id="4">
<method name="open"><![CDATA[var xhttp = new XMLHttpRequest();]]></method>
<method name="close"><![CDATA[var xhttp=null;]]></method>
</script-data-source>
</data-sources>
<data-sets>
<script-data-set name="DataSet" id="5">
<list-property name="resultSetHints">
<structure>
<property name="position">1</property>
<property name="name">BookNames</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">BookNames</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">BookNames</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">ScriptedDataSource</property>
<method name="open"><![CDATA[xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
myFunction(xhttp);
}
}
xhttp.open("GET", "XML Files/books.xml", true);
xhttp.send();
function myFunction(xml){
var xmlDoc = xml.responseXML;
var x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
var txt=x.nodeValue;
count=2;
}
]]></method>
<method name="fetch"><![CDATA[if(count<2){
row["BookNames"]=txt;
count++;
return true
}
else return false;]]></method>
</script-data-set>
</data-sets>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<table id="6">
<property name="dataSet">DataSet</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">BookNames</property>
<text-property name="displayName">BookNames</text-property>
<expression name="expression" type="javascript">dataSetRow["BookNames"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<column id="15"/>
<header>
<row id="7">
<cell id="8">
<label id="9">
<text-property name="text">BookNames</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="10">
<cell id="11">
<data id="12">
<property name="resultSetColumn">BookNames</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="13">
<cell id="14"/>
</row>
</footer>
</table>
</body>
</report>
</pre>
<p>Can you suggest any method, to open the XML file in BIRT using javascript?</p>
<p>or am I doing scripting in the wrong method of Datasource?</p>