Jump to content
We've recently updated our Privacy Statement, available here ×

Is it possible to share Javascript between (say) dataSourceExpressions?


srhaque

Recommended Posts

I have some <subDataset>s with <dataSourceExpression>s containing moderately complex Javascript, e.g.:

..<dataSourceExpression><![CDATA[(function () {// TODO: See https://community.jaspersoft.com/questions/1112616/nested-table-data-source-woes-jsoninputstream-and-reportdatasource-seem-brokenfunction get_definitions(algorithm) {    // Find the right PayOp.    var ops = JSON.parse($F{top}.get("payop"));    var opId = null;    ...}etcetcetc}).apply()]]></dataSourceExpression>..[/code]

I'd like to be able to reuse the get_definitions() function in other <dataSourceExpression>s. Is there a place where I can put the function one copy of the code is enough? Going further, is it possible to share:

  1. functions between (say) dataSourceExpressions and textFieldExpressions?
  2. vars between any of the above?

I guess another way to state the question is "What are the scope rules for Javascript?".

Thanks, Shaheed

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello Shaheed,

I don't think it's possible to add JS files to the studio to reuse. You can add JAR's and java classes to the classpath but not javascripts. To make things easier you can define a custom expression in Window -> Preferences -> Jaspersoft Studio -> Editors -> Expression editor. You can then re-use the expression by picking it in User Defined Expressions folder in Expression Editor. This is not code reusability but it could make it easier to work.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...