Chain scripts, passing data from one to the next - or something

  • I have the following template:

            <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
                {#asset ../PatHeader.css @encoding=utf8}
            <script type="text/javascript">
                var reportName = 'Active Antibiotics';
            {{#each patients}}
            <div style="margin-bottom: 10px; width: 900px;">
                <div style="margin-left: 10px; margin-right: 10px; font-size: 12px;">
                    {#child ../PatientHeader @data.currentPatient$={{{childTemplateSerializeData ./this}}} }
                new stuff here

    A script is called that gets patients and some additional data in order to fill out a header. This will be used in all reports that I'll be making. I would like to pull in another script, using at least the patient IDs of the first script in the WHERE clause of the second to pull in the additional data that will be specific to the report (and put it where I've added the words "New stuff here". I see that I can simply add more scripts to the scripts section of a report template, but how can I pass data from one script to another script and ensure that the first finishes before the second begins in a modular way like I described?

  • administrators

    you can just use the req object that is available in the parameters of the script, it is an object so you can put there some values and those values will be available for the next scripts of the template, scripts runs sequentially (one by one) so you only need to define the order that you want when assigning the scripts to the template.

    0_1562007422581_Captura de pantalla 2019-07-01 a las 1.56.21 p.m..png

    first script

    function beforeRender (req) {
      // after all the work you have done you can set some property in = ids

    the second script

    function beforeRender (req) {
      // should be available here, so you can use it

  • Awesome. Thanks. I'll try it out.

Log in to reply

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