Subreport - trying to call and run from main report



  • Hi all ... I believe I'm completely overthinking this issue, but I'm trying to simply run a subreport in a separate window by clicking on a button or link from my main report. Eventually, I'd like to pass an accountID into the subreport and only run for that subset, but for now, I'd like to just get my secondary/sub report to render.

    Here's the playground entry I've set up.
    https://playground.jsreport.net/w/dqueubed/vkEiLVmu

    Thanks in advance.

     - Roger

  • administrators

    hi @dqueubed

    your code looks fine so far, actually, i think there is a bug in our code, I've noticed that there is a mistake when resolving the url with the browser client when executing this playground.

    I will check a fix for this, to be clear the issue seems to be more related to the execution on the playground so I guess you can also try to run the report locally, it should work fine there.



  • Thanks so much. Actually, I first came across it locally and then replicated it in the playground. I always believe it's me doing something wrong, so any thoughts or directions is always greatly appreciated.

    Thanks again, and I look forward to your findings.


  • administrators

    i've tried with jsreport 3.11.3 locally and it is rendering the subreport, i've used the same code on playground. can you verify?

    here you have a video in which i show how it is working
    showcase.mp4



  • @bjrmatos ... looks like I'm running 3.9 locally and should probably update. That said, it does not run for me in the playground. I'm assuming the playground is 3.11 as well?


  • administrators

    @dqueubed to be clear we have not landed the fix yet, we have it but it is not published.

    yes, the playground is on 3.11 now but still does not contain the fix, the video I am showing is to demonstrate how it works on 3.11 locally (without any fix applied).



  • @bjrmatos ... aaahhhh, ok gotcha. I guess that also explains why I can't seem to update my local version to 3.11 - tried a few times using online instrux but when I fire up JSReport is still says I'm on 3.9 <thumbs_up>. Also, in the video when you changed the recipe to HTML and the sub report ran only showing the text "Amin" ... I am indeed seeing THAT as well. Not rendering the results, but only showing the Amin response.

    q: what do you need me to do here?

    Happy to provide details, test, or ???? ... just let me know. As always, thanks so much ... very appreciative of your time and assistance. :-)


  • administrators

    but for now, I'd like to just get my secondary/sub report to render

    I focused on the issue that you were not able to render the subreport, I thought, that was your main problem so far, that you were just trying to make the render happens without any data (for the testing), but now that it is clear that the render happens let's focus on the next.

    Also, in the video when you changed the recipe to HTML and the sub report ran only showing the text "Amin" ... I am indeed seeing THAT as well. Not rendering the results, but only showing the Amin response.

    yes, it only shows the text "Amin", but that makes sense because you are not passing more data in your code. (as mentioned I thought you were just trying to make the render happen first so i did not give you more advice about how to make the data available to the subreport)

    jsreport.render({
                        template: {
                            name: 'msub_rptSub'
                        },
                        data: {
                            name: 'msub_sub',
                            detailID: 'detail id data goes here'
                        }
                    })
    

    here you have and example of what you can do to pass the sub data, it is one of the many things you can, in this example, I am doing it by loading from the data entity you have available there.

    I think this gives you the general idea, you can tweak or change it depending on your needs. please remember that although the example is available on playground, it is not expected to work there right now (until we land the fix), so try it locally.


  • administrators

    also, pay attention to this part when trying it locally and put that jsreport.serverUrl in a comment

    0_1682538035394_Screenshot 2023-04-26 at 2.40.14@2x.jpg



  • Thanks @bjrmatos ... trying this now.



  • @bjrmatos ... ok, here are my 2 reports running locally in their entirety. From my main report (msub_rptMain) you can see I have the detail function coded with the template and datasource. Running msub_rptMain yields this ...

    0_1682540046112_upload-8f03b1be-9a0e-484a-9fce-76e0ff479df0

    The subreport (msub_rptSub) looks like this when it's been run as a standalone, using msub_sub for a dataset.
    0_1682540126449_upload-38adc142-5056-4c61-b3c0-1e8b9fe7719c

    However, clicking the "drill down" button from the main report doesn't actually run the report ... it simply yields the Amin string I have set to let me know if I'm (programmatically) in the right location.
    0_1682540284375_upload-dc7c2386-6352-425a-967b-9f8af21d8c85

    I should be seeing the entire report being generated, right?


  • administrators

    I should be seeing the entire report being generated, right?

    yes, if you apply the changes I made in the example, you should see the sub report rendering as you would expect

    testing subreport.mp4



  • @bjrmatos ... <DOH>
    Man ... I apologize. I didn't fully understand that you'd made adjustments in the playground :-( Anyway, indeed, I was able to copy and run the changes successfully.

    qq: is this how I need to do it moving forward? Or is there a patch/fix/alternative way I should look to do this going forward?

    I know there are more people to support than just myself, and I genuinely appreciate you taking all this time with me. It's very much appreciated.

    Thanks again, and let me know.


  • administrators

    qq: is this how I need to do it moving forward? Or is there a patch/fix/alternative way I should look to do this going forward?

    well, it depends, I am just showing how to pass the data to the subreport the easy way, based on your data entities, however, this does not mean that it is the approach you should take in production. after all the data entities are used more for testing, because on production you will feed the report with your own data (which is likely to be dynamic and not static like the data entity).

    the main question here will be how you will get the data for the subreport, in the example i shared i get it from your data entity, but that is just for testing, in real world you can do either of the following:

    • fetch the data for the subreport before you call the render of the subreport, this way you do http request (from the browser) and communicate with your server to get the needed data

    or

    • when calling the render of the subreport pass an id, your subreport should have a script attached that takes such id from data and uses it to execute an http request to your server (at the beforeRender step), then in the script you use the results to populate the report data req.data = <http request results here>

    what you choose depends on what looks easier for you, and also if the communication with your server is already secure from the browser, if not then the solution with the script looks better because you can hide the http credentials that your server probably needs to authenticate and return correct response.



  • @bjrmatos ... great food for thought. We do indeed feed data to our reports dynamically and render from a script, but I'm always curious about options and other opportunities, so I may mess around with the browser-based method as well. In all instances, I am most appreciative of your help here. Thanks as always for your support ... you guys are awesome.


Log in to reply
 

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