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


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

<dataSourceExpression><![CDATA[(function () {
// TODO: See
function get_definitions(algorithm) {
    // Find the right PayOp.
    var ops = JSON.parse($F{top}.get("payop"));
    var opId = null;

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
Joined: Mar 16 2018 - 1:29pm
Last seen: 1 year 5 months ago

1 Answer:


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: 1 month 2 days ago