Geocortex Reporting allows users to generate reports that accept JSON data sources. This functionality can enhance system integrations and improves reporting processes! Additionally, it provides a means to dynamically supply JSON data to PDF reports so it can be interpreted at runtime.
This Geocortex Tech Tip will explain how to generate reports that accept JSON data. Further, it will demonstrate how to set up workflows that dynamically generate JSON and pass that data into Geocortex Reporting.
Video Transcription:
Hey everyone, my name is Patrick Fingler, and in this Tech Tip video, I’m going to highlight how you can generate reports that accept JSON data sources using Geocortex Reporting. This is a great method if you need to integrate with different systems or if you want to dynamically supply JSON to a PDF report and interpret those attributes at runtime. If that sounds interesting let’s dive in further!
Alright, so let’s get started! Here you can see I’ve got some sample JSON that I’ve created. This is just some JSON, including some work order features which are part of an Esri feature set.
If you scroll down here, you can see that raw JSON and when it looks like kind of formatted. You can see here we’ve got six “features”, or an array of features. And inside of a feature you can have multiple “attributes” as well as “geometry”, point geometry, associated to each feature. So, each feature is going to have its own list of attributes and so on.
Let’s say I have this JSON, and I want to now generate a report based on it. We’ll navigate to Geocortex Reporting. The first thing you want to confirm is that you’re using Geocortex Reporting 5.13 or greater because that’s the version of reporting where we introduced this capability.
If you navigate to data sources, you’ll click “Add Data Source”. This is where we can insert a JSON data source. We can connect to ArcGIS data sources, non-spatial databases, and now we’ve got the ability to connect to raw JSON.
So, here I’ll supply my data source name. I’ll call this my “Work Orders JSON Data Source” and now I can supply some raw JSON. Here you can see this is the structure of the JSON. Again, we’ve got an array of features, attributes and so on. I’ll eventually click save, I first just wanted to mention that you don’t need to have the underlying values of your JSON. Really all we need is the schema of the JSON in place. But, for testing purposes it is often quite nice to just have some sample JSON in place. So, I’m going to click “Save”.
And now that that’s saved, I’ve got a blank report. I can go ahead and click “Add Data Source”. And now I’ve got the ability to choose a “JSON” data source. We’ll click “Next”.
You can see these are some of the JSON data sources that I have available. I’m going to select my “Work Orders JSON Data Source” and you can see here that this kind of reviews the schema of that JSON. So here we can see we’ve got our “features” array and inside of that features array you’ve got “attributes”. These are all the attributes available, and these are all the “geometry”. You can choose what items you might want to include in your report. So, maybe I just want to generate a report that loops over this features array.
So, I’m going to go ahead and click “Finish” and we’ll see that that gets populated. Here I’ve got my “JSONDataSource1”, here I’ve got my “features” and then here I’ve got my “attributes” as well as my “geometry”. So, I’m going to go ahead and add these. Maybe I want to include the “objectid”, the “inspector” and the “template” for the work orders that were included in this JSON object.
I’m actually going to click delete, and I’m also going to add the “geometry”. I can see that this geometry is also contained within this feature. So, let’s add that as well.
You can see here this is going “attributes.objectid” and then also “geometry.x” and “geometry.y”. Because I have some sample JSON data within my data source, I can just click the “Preview” button and we should see six work orders coming from that underlying JSON object.
So, there you go, we can see we’ve got six work orders. These are the object ID’s, the inspector names, the work order type and the coordinates listed there.
Now this is a very simple example. How you actually implement this in practice is you’re typically going to want to have a workflow which is used to dynamically generate that JSON. Whether you’re integrating with a rest API and getting some JSON back, or if you want to manipulate some data using workflow, create some JSON and then pass that to a report, that typically would be done on the workflow side.
So, what I’ve done here is I’ve created a workflow in Geocortex Workflow that uses some of our Maximo custom activity packs. If you’ve licensed Geocortex Workflow, you can get these for free on our GitHub. I just want to show an example where we’re actually sending a web request to a rest API, we’re dynamically retrieving some JSON and then passing that to a report.
So, here I’ve got a login form which will allow me to log into Maximo. Once I’ve initiated that login, we’ll create what’s called a Maximo “Service” which I’ve supplied to this “Get Maximo Resources” activity. What this essentially does is it issues a web request to Maximo. I want to find all of the work orders, I can specify the top 50 of them by setting “Page Size” to 50, and I want to get just these three “Select” attributes – the “workorderid”, the “description” and “reportedby”. And then that’s going to pass back a JavaScript object, or an array of features, or work orders. Here I also “Convert to JSON” so I can then pass that to my report data source object. I’ll also touch on where you configure this on the reporting side as well.
Here we can see we’ve got a “Run Report” activity and you’ll see here we’ve added this “Data Sources” option. You can now expand this, and you have to kind of construct this object where you specify the name. This has to match the name of the JSON data source in your Geocortex Reporting designer. Here we can go to my “Data Sources” tab in Geocortex Reporting, and if I scroll down, I’ve got a “Maximo JSON” data source. This is the JSON schema coming from my Maximo activity. So, I’ve supplied that in here and back in the workflow we’re going to dynamically pass additional JSON. So, that’s coming from a JavaScript object, which is coming from our get Maximo resources activity. That’s important. This name in the Geocortex Workflow “Input Editor” has to match the name of your “Data Source” in Geocortex Reporting.
Let’s go ahead and run this. I’ll click “Start” and run it.
Let’s rerun this and clear our console and network tab. It’s going to ask me to log in. I’ll enter my credentials and click “Login”. Let’s just clear the console network tab again.
Here you can see we’re actually issuing a web request to Maximo and now we’re generating a report.
You can see that it’s all done generating; we can open this up and we can see we’ve got a report that has the top 50 work orders getting pulled from Maximo. A really basic report here. We’ve got those three attributes.
Where is this actually getting fed? If we look in the console we can see here once we find our “getMaximoResources” activity that these are the “inputs” that I supplied. And these are the “outputs”, which are essentially a JavaScript object which has an array of “members” which have some attributes, who it was “reportedby”, the workorderid” and the “description”.
If we go to the network tab, we can see we’re actually issuing web requests to Maximo. If we were to review this, we can see this is going to a rest API and it’s returning back this JavaScript object which we can then extract the JSON from which is where I supplied this parameter here. I supplied that JSON in here and then it’s really the same process. I supplied that JSON, I added that data source. You can see here we’ve got our member array and then here I’ve just supplied those three attributes to the report.
There are a few steps involved, but hopefully that helps you start dynamically passing your own JSON objects to Geocortex Reporting. I know a lot of customers have been waiting for this functionality, so hopefully that helps. Bye for now!
Want to learn more about building reports with Geocortex Reporting? Click the button below for more information on the capabilities of Geocortex Reporting.