Running reports with REST API
When a user makes a selection from a list of locations, the application verifies if the selected report already exists and if it is recent. If the report is older than the report refresh time or if the report does not exist, the report is generated with the executeReport function.
The following overview describes this functionality in the example application:
*Check if the report design file id exists.
*If the file id is not known, a search is made for the file id of Flight Performance.rptdesign; the design file that generates the BIRT report visualizations.
*Define parameters to run the report design and generate the report for the selected state.
*Run the loadBookmarks function to display the report visualizations on the web page.
The executeReport function searches for the BIRT report design file id if the id does not already exist with the following code:
$scope.executeReport = function(fileName, region, state) {
console.log("fileName = " + fileName);
var params = {
search : '/Home/Flight Delay App/Flight Performance.rptdesign',
authId: $rootScope.AuthId
};
if (!$rootScope.reportId ) {
API.DownloadReport.query(params,
function (dataResponse) {
$rootScope.reportId = dataResponse.ItemList.File[0].Id;
A successful file search returns a response body similar to the following:
{
"ItemList": {
"File": [
{
"Id": "882200000100",
"Name": "Flight Performance.rptdesign",
"FileType": "RPTDESIGN",
"PageCount": "0",
"Size": "400400",
"Version": "1"
}
]
},
"TotalCount": "1"
}
Once the file id is known, the id is used to generate a report from the report design file using the following code:
var paramValues = {"ParameterValue" :
[
{"Name" : "Region","Value": region},
{"Name" : "State", "Value": state}
]
};
params = {
reportsId : dataResponse.ItemList.File[0].Id,
paramValues : angular.toJson(paramValues, false),
saveOutputFile : true,
replaceExisting : true,
requestedOutputFile : fileName,
authId: $rootScope.AuthId
};
$scope.timestamp = "Generated " + $filter('date')(new Date(), "MM/dd/yyyy 'at' h:mm a");
API.ExecuteReports.post(params,
function (dataResponse) {
$scope.loadBookmarks(fileName);
},
A successful job execution returns a response body similar to the following:
{
"Status": "FirstPage",
"ObjectId": "220710000100",
"OutputFileType": "RPTDOCUMENT",
"ConnectionHandle": "bAq+y9HJrv5y7XC/gX7MO721WvOI/w6jmbZwg7PYF19Cq3057d+JTeUKSSPpu8CJEdtWledo6r5Fb4yX4Ucvyt84/3qNdvlyqKFp41x9MxeCmRgzAYm90ztm3Lyfjqx82DvON58eYK8rSKFmLiwjk8G3yjwNvQ0UG0eLmAm6yieKHTpWon9M95UJcKNnCtdE6HFYH+iv3kbbC1t2L7opIInDUZnxKjZ6YZgrmUYKgYPKVi0rSGjMWS1obFISqHPASoQcmOHMSkyry94aXKCn+eLVBZJu9VSY"
}
The executeReport function then extracts the bookmarked visualizations from the generated file.
See the source code for the complete example.