jsreportonline and scripts



  • Is there a preferred way (JSReport way) to create a script that is reusable within report specific scripts? I had locally created a set of methods that did all of my HTTP callings and used them in specific scripts for specific reports. This allowed me to not have to repeat the ceremony of working with a module like HTTP in each report that I create. I achieved this by inspecting the filesystem and requiring through the path to the content file. Currently, as I can tell, jsreportonline does not have allowedModules: "*", so I think I am stuck.

    Am I looking to do more than what is currently (or ever) capable? Or is there a way that I have not understood through the documentation?

    Scripts

    1. API-Access = abstraction over HTTP/Request/whatever
    2. Invoice Script -> require(API-Access)
    3. Summary Script -> require(API-Access)

    Reports

    1. Invoice -> references "Invoice Script"
    2. Summary -> references "Summary Script"

    Thank you in advance


  • administrators

    Is there a preferred way (JSReport way) to create a script that is reusable within report specific scripts?

    we usually recommend to create an asset with all your shared functions, then you just need to import the asset in every part where you need the functions. so your abstraction can be in an asset and you will be able to import it in different scripts.

    Currently, as I can tell, jsreportonline does not have allowedModules: "*", so I think I am stuck.
    Am I looking to do more than what is currently (or ever) capable? Or is there a way that I have not understood through the documentation?

    unfortunately yes, right now jsreportonline does not allow importing custom modules in scripts, because this has some security implications for our server. however i think require('request') is allowed inside a script, so you can use that in your abstraction.

    i think it is not clear what are the allowed modules in jsreportonline, maybe we should add an explicit list in the jo FAQ cc @jan_blaha



  • Thank you for verifying what I thought. Unfortunately, I will just have to replicate logic across each custom script. Not a problem now, but being able to modularize repeated functionality could be useful across many reports.


  • administrators

    Unfortunately, I will just have to replicate logic across each custom script. Not a problem now, but being able to modularize repeated functionality could be useful across many reports.

    have you tried the asset approach? this is the way to have repeated functionality in one place and then use it in different scripts.



  • My understanding was that assets are presentation artifacts, I missed the "custom scripts" mentioned in the one sentence. Thank you for your help, this should allow for some leniency. My initial feeling was that "{#asset some-asset.js}" would work within the script.


  • administrators

    ๐Ÿ‘Œin case it is not clear, here is an example of what i said above



  • I figured it out (tested in sandbox), thank you for all the help


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.