Jump to content

Dynamic json url api data adapter passed to subreport?


tony.belfiore

Recommended Posts

I have a main report with one subreport (for each item) in the main report. My main report is working fine.

My subreport needs to use a different data adapter (than the main report) by calling a REST API (with header and param meta data).

It's important to note that the Base Url of the data adpater is dynamic for each subreport item.

For example, the Base Url for one subreport with item Id 12345 would be -> https://my.api.com/api/v1/12345/image

So, I need a dynamic data adapter for each element in the main report so the subreport can make the right API call. I also need to pass in things like API parameters and headers.

Is something like this possible?

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

I was able to solve this question myself by gleaning some information hidden at the bottom of this article:

https://community.jaspersoft.com/documentation/tibco-jaspersoft-studio-user-guide/v720/connecting-web-service-using-json-data-adapt-0

Basically, for my subreport, I was able to dynamically pass in a baseurl parameter (the name could be anything, but I happened to pick baseurl) from the main report (e.g. https://my.api.com/api/v1/12345/image) for each item in the main report. The solution was properly configuring the subreport dataset and query. Note that the subreport can be seeded by a default JSON API data adapter that has a hard coded baseurl (see on screen as File/URL in the data adapter setup). You can override this hardcoded url by going into the subreport Dataset and Query Dialog and clicking on the Parameters tab at the bottom. You can add a baseurl Parameter (which the main report will use to pass in the values), and it is important to note that you add a Data Url property type on the parameter (which is what I happened to see in the article above, but it wasn't used in that article directly).

If you do this correctly, you should see a value of baseurl for the "Data URL" property in the "Data Adapter" tab at the top of the Dataset and Query Dialog of the subreport.

Granted, I may hit performance issues. I have no idea how well Jasper will respond to this complex configuration and potentially many API calls.

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...