# Report execution

Executing a report with the ActiveReportsJS api

## Content

### Page Report class

The [Page Report class](https://developer.mescius.com/activereportsjs/api/classes/Core.PageReport) represents a report instance that takes a report template, parameters values, and runtime configuration as an input and provides properties and methods to produce the report output.
The Page Report class constructor has the optional `options` argument, which is an object with three properties. Two of them are for internal usage only, but the third one called `memoizeData` determines whether the report data should be stored and reused in subsequent runs of a report. When set to `true`, which is the default value, the report data will be stored and reused for future runs, improving performance by reducing the need to re-fetch the data. When set to `false`, the report data will not be stored and will be fetched fresh each time the report is run. However, if data bindings of a report are dynamic and depend on [parameters](/activereportsjs/docs/ReportAuthorGuide/Report-Parameters) values that can vary for subsequent runs, the `memoizeData` value is ignored. Below is the code example of initializing a new instance of the `PageReport` class.

```ts
import {Core} from "@mescius/activereportsjs";

var report = new Core.PageReport({
    memoizeData: true
});
```

### Loading Report Template

You can use the `load` method of the `PageReport` class to set the report template and configure the runtime environment that is required for report execution. The first argument of the `load` method is either a URL that retrieves the report template or an object of [Report type](/activereportsjs/docs/DeveloperGuide/api/working-with-report-templates). The second argument is optional, and it's an object with several properties:

* `resourceLocator` – the implementation of the [Resource Locator](/activereportsjs/docs/DeveloperGuide/ActiveReportsJSViewer/LoadingReports/ResourceLocator)
* `environment` – an object that has the `ReportName` property that can be referenced in a report using the `{&ReportName}` [expression](/activereportsjs/docs/ReportAuthorGuide/Expressions).

The `load` method retrieves a [Promise object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) because it might fetch the report template from a remote resource. Consequently, the code that invokes the `load` method should wait for the returned promise to be fulfilled, for example:

```ts
import {Core} from "@mescius/activereportsjs";

var report = new Core.PageReport();
await report.load(`assets/Products.rdlx-json`, {
  environment: {
    ReportName: "Product Catalog",
  },
});
```

### Setting parameters values

The `PageReport class` has the `reportParameters` property, which includes methods for setting, validating, and resolving parameter values. When providing parameter values, always use an array of atomic values (i.e., numbers, strings, boolean values, or dates), even for single-value parameters.
Here's an example that demonstrates how to create an instance of the `PageReport` class, load the report template, and set parameter values:

```ts
import {Core} from "@mescius/activereportsjs";
var report = new Core.PageReport();
// Load the report template and set parameter values
await report.load(`assets/Products.rdlx-json`, {
    reportParameters: [{
        Name: 'Header',
        Value: ['Product List'] // string single value parameter
    }, {
        Name: 'SupplierIds',
        Value: [1, 2, 3] // integer multi value parameter
    }]
});
```

Alternatively, you can use the `applySteps` method of the `reportParameters` object for setting parameter values in various advanced scenarios:

```js
var report = new Core.PageReport();
await report.load(`assets/Products.rdlx-json`);

// Set parameter values using the applySteps method
report.reportParameters.applySteps([
  {
    Name: "Header",
    Value: ["Product List"], // string single value parameter
    Type: "Set",
  },
  {
    Name: "SupplierIds",
    Value: [1, 2, 3], // integer multi value parameter
    Type: "Set",
  },
]);
```

### Running a report

After a report template is loaded and parameters values are set, the code could call the `run` method of a `PageReport` instance. It returns the `Promise object` that is fulfilled with the `PageDocument` instance:

```ts
import {Core} from "@mescius/activereportsjs";

const report = new Core.PageReport();
await report.load(`assets/Products.rdlx-json`);
report.parameters["Header"].values = ["Product List"];
const document = await report.run();
```