Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343338 - before_open causing strange errors
Summary: before_open causing strange errors
Status: RESOLVED WORKSFORME
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 2.2.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.4.0   Edit
Assignee: Birt-ReportDesigner CLA
QA Contact: Sissi Zhu CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-20 00:40 EDT by Low Kian Seong CLA
Modified: 2014-03-03 18:44 EST (History)
3 users (show)

See Also:


Attachments
before_open_script (939 bytes, text/plain)
2011-04-20 00:42 EDT, Low Kian Seong CLA
no flags Details
Query used in DataSet (5.32 KB, text/plain)
2011-04-20 00:43 EDT, Low Kian Seong CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Low Kian Seong CLA 2011-04-20 00:40:01 EDT
Build Identifier: 2.2.6

I have an SQL query with params which produces error in before_Open script that I have tied to the dataset, but only for this particular report

Reproducible: Always

Steps to Reproduce:
1.create a dataSet using the query
2.try to reset the parameters
Comment 1 Low Kian Seong CLA 2011-04-20 00:42:31 EDT
Created attachment 193648 [details]
before_open_script

before_open script used with the dataset
Comment 2 Low Kian Seong CLA 2011-04-20 00:43:26 EDT
Created attachment 193649 [details]
Query used in DataSet

Query used with DataSet when error occurs.
Comment 3 Low Kian Seong CLA 2011-04-20 00:44:44 EDT
The error that I get is this:


A BIRT exception occurred.
  Plug-in Provider:Eclipse.org
  Plug-in Name:BIRT Data Engine
  Plug-in ID:org.eclipse.birt.data
  Version:2.6.2.r262_v20110215
  Error Code:data.engine.FailToExecuteScript
  Error Message:Fail to execute script in function __bm_beforeOpen(). Source:
------
" + var multipattern=/![a-zA-Z_]*/gi;
var multivars = this.queryText.match(multipattern);

if(multivars){
	for(i=0;i<multivars.length;i++)
	{
		var curvar = multivars[i].substr(1);
		var cleaned = params[curvar].toString().replace(/\'/g,"\\'");
		var toreplace = "'" + cleaned.replace(/,/g,"','") + "'";
		var target=multivars[i];
		if(toreplace=='All'){
			target=" in ("+multivars[i]+")";
			toreplace=" not in ('"+multivars[i]+"')";
		}
		this.queryText = this.queryText.replace(target,toreplace);	
	}
	logToDebugWindow(toreplace);
}

var multipattern=/#[a-zA-Z_]*/gi;
var multivars = this.queryText.match(multipattern);
if(multivars){
	for(i=0;i<multivars.length;i++)
	{
		var curvar = multivars[i].substr(1);
		var toreplace = params[curvar].toString();
		var target=multivars[i];
		if(toreplace=='-1'){
			target=" in ("+multivars[i]+")";
			toreplace=" not in (-1)";
		}
		this.queryText = this.queryText.replace(target,toreplace);
	}
} + "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError: Cannot call method "toString" of undefined (/report/data-sets/oda-data-set[@id="522"]/method[@name="beforeOpen"]#8)
 Script source: <inline>, line: 0, text:
__bm_beforeOpen()
Comment 4 Xiaoying Gu CLA 2011-04-26 01:11:04 EDT
Can you reproduce this error if have below contents in your scirpts:
        var toreplace = params[curvar].toString();
        var cleaned = params[curvar].toString().replace(/\'/g,"\\'");

And what's the defination of params[curvar], type and value when run the report?
Comment 5 Linda Chan CLA 2014-03-03 18:44:37 EST
See comment #4.
If the issue still exists for you, please feel free to reopen the bug with more details on how to reproduce.