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

0

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-broken
function get_definitions(algorithm) {
    // Find the right PayOp.
    var ops = JSON.parse($F{top}.get("payop"));
    var opId = null;
    ...
}
etc
etc
etc
}).apply()]]></dataSourceExpression>
..

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

srhaque's picture
13
Joined: Mar 16 2018 - 1:29pm
Last seen: 1 week 3 days ago

1 Answer:

0

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.

Friendly User's picture
Joined: Oct 8 2009 - 5:59am
Last seen: 2 days 11 hours ago
Feedback
randomness