case 4302
This commit is contained in:
@@ -151,12 +151,12 @@ Use of the `ayPrepareData` function is optional and most reports will not requir
|
||||
This is the default ayPrepareData method:
|
||||
|
||||
```javascript
|
||||
async function ayPrepareData(ayData) {
|
||||
return ayData;
|
||||
async function ayPrepareData(reportData) {
|
||||
return reportData;
|
||||
}
|
||||
```
|
||||
|
||||
`ayData` parameter is an object containing three keys with data required to render the report and it's format is detailed below in the [Report Data Objects](#report-data-structure) section.
|
||||
`reportData` parameter is an object containing three keys with data required to render the report and it's format is detailed below in the [Report Data Objects](#report-data-structure) section.
|
||||
|
||||
Note that the SAMPLE DATA section of the user interface in the report designer shows the raw data _before_ it is passed to this function, not how it would look _after_ this function is run. If you need to see how the data is shaped after a ayPrepareData you can make use of the `ayJSON` helper documented below to view the raw data on the rendered report itself.
|
||||
|
||||
@@ -204,7 +204,7 @@ Importing of report templates is done from the administration report templates [
|
||||
|
||||
When a report template is processed, business object data is provided to the template along with other data. Some of this data is used internally by the provided helpers and you have full access to these data values in your templates, Handlebar helpers and PrepareData scripts.
|
||||
|
||||
In the `ayPrepareData` function on the Prepare Data tab of the report designer the `ayData` parameter contains three properties detailed below you can use in preparing data:
|
||||
In the `ayPrepareData` function on the Prepare Data tab of the report designer the `reportData` parameter contains three properties detailed below you can use in preparing data:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -473,9 +473,9 @@ Note that you need to tell AyaNova which translation keys to pre-fetch before re
|
||||
For example, let's say you wanted to display the translation for Customer and WorkOrder, you would insert a call to get the translations as follows:
|
||||
|
||||
```javascript
|
||||
async function ayPrepareData(ayData) {
|
||||
async function ayPrepareData(reportData) {
|
||||
await ayGetTranslations(["Customer", "WorkOrder"]);
|
||||
return ayData;
|
||||
return reportData;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -507,12 +507,15 @@ The `ayGroupByKey` function is provided to group the report data by a key name i
|
||||
The following shows using the ayGroupBy function in the ayPrepareData to reformat a Customer Unit List into groups by Customer name which is provided in the CustomerViz property:
|
||||
|
||||
```javascript
|
||||
async function ayPrepareData(ayData) {
|
||||
async function ayPrepareData(reportData) {
|
||||
//send the raw report data to the groupByKey function which will return a new array grouped by the key name provided
|
||||
ayData.ayReportData = ayGroupByKey(ayData.ayReportData, "CustomerViz");
|
||||
reportData.ayReportData = ayGroupByKey(
|
||||
reportData.ayReportData,
|
||||
"CustomerViz"
|
||||
);
|
||||
|
||||
//return the data into the pipeline to send to the report template
|
||||
return ayData;
|
||||
return reportData;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -532,7 +535,7 @@ While it is possible to login via a script using alternate credentials and acces
|
||||
|
||||
### API convenience functions
|
||||
|
||||
Two functions are provided with the report to assist with API usage from your ayPrepareData custom function:
|
||||
The following functions are provided to assist with API usage from your ayPrepareData custom function:
|
||||
|
||||
_GET_
|
||||
|
||||
@@ -549,27 +552,40 @@ The ayPostToAPI function works with POST routes in the API:
|
||||
The `token` parameter is optional and if not provided will be set by default to the current User's access token.
|
||||
The `route` parameter will be automatically prepended with the server local api url if you do not provide the starting "http" in the URL. Do not include the initial slash.
|
||||
|
||||
_PUT_
|
||||
|
||||
The ayPutToAPI function works with PUT routes in the API:
|
||||
|
||||
`async function ayPutToAPI(route, data, token) {...`
|
||||
|
||||
The `token` parameter is optional and if not provided will be set by default to the current User's access token.
|
||||
The `route` parameter will be automatically prepended with the server local api url if you do not provide the starting "http" in the URL. Do not include the initial slash.
|
||||
|
||||
_Parameters_
|
||||
|
||||
The `route` parameter is required and will automatically include the current API server URL prepended if not provided (it looks for "http" at the start). For example you can specifiy the `route` parameter as simply the end portion of the route without the slash: "server-info" or the full route to the server from the server URL meta property. For example the full route to fetch data from the `server-info` API route can be constructed as follows:
|
||||
`` let route=`${ayData.ayServerMetaData.ayApiUrl}server-info`; ``
|
||||
The `route` parameter is required and will automatically include the current API server URL prepended if not provided (it looks for "http" at the start).
|
||||
|
||||
The `token` parameter is optional and if not provided will be set by default to the current User's access token or you can specify it by using the authorization token provided in the Client data as follows:
|
||||
`let token=ayData.ayClientMetaData.Authorization;`
|
||||
For example you can specifiy the `route` parameter as simply the end portion of the route without the slash: "server-info" or the full route to the server from the server URL meta property.
|
||||
|
||||
For example the full route to fetch data from the `server-info` API route can be constructed as follows:
|
||||
`` let route=`${reportData.ayServerMetaData.ayApiUrl}server-info`; ``
|
||||
|
||||
The `token` parameter is **optional** and if not provided will be set by default to the current User's access token or you can specify it by using the authorization token provided in the Client data as follows:
|
||||
`let token=reportData.ayClientMetaData.Authorization;`
|
||||
|
||||
The `data` parameter of a POST route differs for each route and is documented in the developer's API documentation.
|
||||
|
||||
The following is an example of accessing the API with both a GET and POST action:
|
||||
|
||||
```javascript
|
||||
async function ayPrepareData(ayData) {
|
||||
async function ayPrepareData(reportData) {
|
||||
//Example API GET method
|
||||
//to fetch data from API server
|
||||
//using the "server-info" route
|
||||
|
||||
//Add the data to the main report data object
|
||||
//so it's available to the template
|
||||
ayData.myData = {
|
||||
reportData.myData = {
|
||||
ServerInfo: await ayGetFromAPI("server-info")
|
||||
};
|
||||
|
||||
@@ -579,8 +595,11 @@ async function ayPrepareData(ayData) {
|
||||
//construct the POST object
|
||||
let searchPostData = { phrase: "fish" };
|
||||
|
||||
ayData.myData.SearchResults = await ayPostToAPI("search", searchPostData);
|
||||
return ayData;
|
||||
reportData.myData.SearchResults = await ayPostToAPI(
|
||||
"search",
|
||||
searchPostData
|
||||
);
|
||||
return reportData;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user