Referencing Scripts in Same Folder with Postgres Storage

  • Hello,
    I'm curious if someone can help me reference (in js) a script in the same folder on JSReport v2.5.0
    I'm using a JSReport server set up by the service REDCap Cloud, so configuration of the server is hidden away from me.

    As far as I can tell no base path has been set up ('./' doesn't seem to reference the directory the script exists in), the entity storage is a Postgres SQL server.
    What full-path should I supply a "require" call to reference script files (i.e. path to data storage)?

    Any help would be greatly appreciated.
    Thank you!

  • Do you mean script inside <script> tag in the template content?

    You can create asset entity and then reference it

    And then in the template use

       {#asset ./myscript.js}

  • @jan_blaha
    Thanks for the reply Jan.
    Yeah, I'm able to reference the asset but I'm still having issues.
    My script asset is using Highcharts JS code and my template includes in the html Head:
    "<script src=""></script>
    <script src=""></script>"

    However, when the asset script, referenced as you suggested, is run I receive the error (renderHospGraph is the function referencing Highcharts):
    "ReferenceError: Highcharts is not defined
    at renderHospGraph (evaluate-user-script.js:246:3)
    at evaluate-user-script.js:75:1
    at Script.runInContext (vm.js:133:20)
    at (/opt/jsreport/node_modules/vm2/lib/main.js:212:72)
    at run (/opt/jsreport/node_modules/jsreport-core/lib/render/safeSandbox.js:183:19)
    at module.exports (/opt/jsreport/node_modules/jsreport-scripts/lib/scriptEvalChild.js:170:5)
    at IncomingMessage.<anonymous> (/opt/jsreport/node_modules/script-manager/lib/worker-servers.js:268:47)
    at IncomingMessage.emit (events.js:203:15)
    at IncomingMessage.EventEmitter.emit (domain.js:466:23)
    at endReadableNT (_stream_readable.js:1145:12)"

    Any recommendations on the proper way to integrate Highcharts JS code from the asset script into the template?

  • It works fine for me.

    Try to run with Debug button in your studio. Maybe you have some js error visible there.

  • @jan_blaha
    Okay, I got it to work actually. Thank you!

    I was also wondering if you had advice about reading from sample data in JSON format?
    After importing my script asset, I'm having trouble trying to pass sample data to a function within the asset.

    My sample data looks like:
    "quarters": [{
    "name": "Q1 2016",
    "patientData": [
    {"dup1": 90},
    {"dup1": 30},
    {"dup1": 20}
    "totalSize": 5,
    "included": 3
    "name": "Q2 2016",
    "patientData": [
    {"dup1": 200},
    {"dup1": 93},
    {"dup1": 100}
    "totalSize": 7,
    "included": 3


  • @jan_blaha
    I'm kind of a Javascript novice so really any help/teaching is greatly appreciated. I'm at the point where I can take the request data via beforeRender in a script and push this data to an array in my JSON sample data.
    My sample data now looks like this:
    { quarters:
    [ { name: 'Q1 2016',
    patientData: [Array],
    totalSize: 5,
    included: 3 },
    { name: 'Q2 2016',
    patientData: [Array],
    totalSize: 7,
    included: 3 } ],
    [ [ 100, 3, 5, 43.84939195509823, 100 ],
    [ 0, 3, 7, 0, 56.15060804490177 ] ] }

    My issue now with using Highcharts visualizations. I'd like to read the vizData from the JSON and render a Highcharts graph with it. I have a function renderDupGraph in one of my assets that if passed vizData, can find the Highchart's library, and can find render <div id='container'> in template that it will create the graph.

    Is it possible to either:

    • Get vizData array with Handlebars syntax as an argument to this Highcharts function inside the template <script> tag?
      • Additionally, this call needs to happen in template so that the Highcharts package can be found from the template <head> and also to find the target <div id='container'>.


    • Import Highcharts into my script and perform the call in an afterRender function?
      • Here I would get data from in afterRender

    Thank you for any guidance!

  • This problem and the solution is described here

  • @jan_blaha
    Awesome Jan, I have things working now. Thank you for your help!

Log in to reply

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