Workaround for Using an External JS Resource in Parameter Script Methods

mwilliams
edited February 11, 2022 in Analytics #1
To access a js function defined in your report's resources, in your parameter scripts, you can use a workaround like this to read the js file, manually.
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
ist = reportContext.getResource("myJSFile.js").openStream();
myjsstring="";
bytesa = new ByteArrayOutputStream();
var c;
while((c=ist.read()) != -1){
bytesa.write(c);
} 
ist.close();
data = bytesa.toByteArray();
value = new String(data);
myjsstring = reportContext.evaluate(value);
<br />
From here, you'll be able to call your function, like you would in any other script area, i.e. myFunction();
Warning No formatter is installed for the format ipb