greenockboy Posted January 25, 2007 Share Posted January 25, 2007 Hi Finally worked out how to pass the current connection to my scriptlet.I have a report with a number of groups.Each group has a number of fields, one of which has a call to a method in my scriptlet, the return string is assigned to the field and displayed.The method contains an SQL query and retrieves data from a table, a different one from the report query.Unfortunately only the field from the first group is being assigned a value.I cannot work out why and am wondering if there is only one call to my scriptlet method regardless of the number of groups.One other thing I am trying to do is pass the value from another field into my scriptlet, but thus far without success.Any pointers on these would be much appreciatedThanksGB Link to comment Share on other sites More sharing options...
richh Posted January 25, 2007 Share Posted January 25, 2007 Passing fields, properties and variables is done using the scripting codes. Example: Code:((myScriptlet)$P{REPORT_SCRIPTLET}).myMethod($F{fieldValue}, $P{REPORT_RESOURCE_BUNDLE}, $V{variableValue)) Note that each parameter is an object (Integer, Boolean, etc.). You can use the conversion methods such as (Integer).intValue() but be sure the value is not null. The validation of the call will see a NullPointerExceptiion but you won't see it. The method just won't be called. Link to comment Share on other sites More sharing options...
greenockboy Posted January 25, 2007 Author Share Posted January 25, 2007 HiJust to say that the cause of the problem was that I wasn't closing the ResultSet at the end of the method.For those that are interested in how to pass the current connection to a scriptlet the steps are shown below.1. Create a method inside your scriptlet. This method should take as a parameter a Connection object and return the appropriate data type.2. Create a call to your scriptlet from the 'Print when expression' editor of a field contained within the report, the call will contain the current report connection.For example if your method is called 'getNames' and it returns a string then use a statement similar to below."Name: " + ((miskey_outer_joinScriptlet)$P{REPORT_SCRIPTLET}).getNames($P{REPORT_CONNECTION}) where miskey_outer_join is the name of the report and miskey_outer_joinScriptlet is the name of the scriptlet. Link to comment Share on other sites More sharing options...
greenockboy Posted January 25, 2007 Author Share Posted January 25, 2007 Hi richh Didn't notice your reply before I posted, thanks for taking the time to respond, it's much appreciated.I'm now looking to paas the field values so I'll give your suggestion a go.Incidently, how have you managed to get spaces between paragraphs in your posting.GB Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now