Hello,
I want to provide the user a button in a form-page that allow to download a Report.
In the example
https://help.five.org/2.7/docs/visual/reports/generating-reports/generating-reports-server-side
The function to generate the report in the backend is attached to a ‘Do Press’ event on a Application button.
And the function to download the report is attached to an ‘On Complete’ event on the same Application button.
I would like to have these functions triggered by a Form-field button, but there is no ‘Do Press’ and ‘On Complete’ events on this kind of button. Is that mean that it is not possible to call these functions on a form field button? The only way is to use a Form-Action button or an Application button?
Actually, it does not seem to be possible to attach server-side function to a form-field button, am I right?
Thank you!
Jean
Hi Jean,
For a form field you could use the display type _Button and then use the On Click (frontend) event and attach your function.
Form Fields | Five | Low-Code For Real Developers
There is an example of using a _Button display type in the Book Club application, it is on a process screen field, however, it operates the same on a form field.
10.3 - Find Books Process | Five | Low-Code For Real Developers
You could then write your backend function, and the frontend function attached to the On Click event can call the backend function through Five’s executeFunction()
executeFunction() | Five | Low-Code For Real Developers
There is a good example of executeFunction() in the Portfolio training application, however, it isn’t attached to a _Button display type.
9 - Call a Server-Side Function From the Client | Five | Low-Code For Real Developers
I hope this gives you a solution you need.
Kind regards,
Jo
Thanks Jo, it works! The difficulty was to find the right parameter in the downloadDataUrl function (result.serverResponse.message instead of result.dataContext.results)
But my report is empty
Since my report is based on a SQL query with parameters, how can I give the parameters to the report? It works fine on the client side when I want to display the report within my application, but the report on the server side does not seem to take into account my three parameters. Here is my server function. The log demonstrates that the parameters received from the client function are filled up properly.
function DownloadInvoiceServer(five, context, result) {
five.setVariable("AdjointKey", context.AdjointKey);
five.setVariable("ArbitreKey", context.ArbitreKey);
five.setVariable("NoFacture", context.NoFacture);
five.log("s-AdjointKey -" + five.getVariable("AdjointKey"));
five.log("s-ArbitreKey -" + five.getVariable("ArbitreKey"));
five.log("s-NoFacture -" + five.getVariable("NoFacture"));
const reportResult = five.executeAction ('FactureReport', {});
if (reportResult.isOk() === false) {
return five.createError(reportResult);
}
five.setVariable("MessageFacture", "Facture générée avec succès.");
return five.success(reportResult.report);
}
Hi Jean,
Sorry, I overlooked this! I’m glad part is working for you!
I’ve put an example together which should help you.
I have a simple query selecting the ProductKey, Name and Price fields and the WHERE clause is using a parameter to know the price.
SELECT
Product.ProductKey,
Product.Name,
Product.Price
FROM
Product
WHERE Price < ?
The parameter is defined on the outside of the query on the Parameters page using five.field, eg {{five.field.LessThan}}
Then I have a function calling executeAction which calls the report like you do, however, instead of passing an empty context we now pass through the LessThan value which gets passed to the query when it executes.
const reportResult = five.executeAction ('LowestPricesReport', {'LessThan' : '3'});
if (reportResult.isOk() === false) {
return five.createError(reportResult);
}
This should make it that you will get results in your report!
Kind regards,
Jo
TestReport2-20250712-222058007379596.fdf (3.4 MB)
Well, I am having serious difficulty when trying to pass parameters from a form to the report query. I have included a sample application for my tests.
1- Using five.selectAction(‘ReportID’) for displaying a report.
To display my report, using a query with a global variable as parameter works fine (Button ‘View report with var as parameter’).
My question: Is it possible to use a query with five.field parameter? In my sample application, the function GenerateReportParamField displays an empty report (Button ‘View report with field as parameter’). The five.field.LessThan is not taken into account.
2- Using five.executeAction(‘ReportID’, {}) for downloading a report.
I tried to reproduce your example with no success. Can you tell me what is wrong with my sample application? How can I bring the five.field.LessThan value to the DownloadReport function?
Your help will be very appreciated.
Jean
Thanks for the example app Jean! I’m looking into it at the moment and will get back to you shortly.
Kind regards,
Jo
TestReport2-20250715-061916471773726.fdf (3.4 MB)
Hi Jean,
Thanks for your patience!
I have attached your sample app again with the changes. I have also listed below what was changed:
- For your ProductsLessThanParamField query, on the Parameters page for the MaxPrice field could you change the Parameter to {{five.variable.LessThan}} previously it was {{five.field.LessThan}}
- Go to Data Views and perform the following changes:
In the Data Source field change the Product table to ProductLessThanParamField (Query) - This is because a table won’t filter on a data view, it needs to be a query.
- Then go to the Data Fields page and for each of the three fields marry up the query field again as they were wiped when the data source was changed, for example, for the ProductKey field select Product.ProductKey in the Field field.
- Once you have done all three fields, go to the Screen Fields page and select your parameter, {{five.variable.LessThan}} in the Linked Parameter field.
- Finally, go to the DownLoadReport function and change line 4 and line 7 to be five.variable rather then five.form.
This will filter your data view and return results when you click your Download Report button.
We did also update your account as there was an issue on our side. Let me know how this goes for you!
Kind regards,
Jo
1 Like
Great! I deduce passing parameters to a query seems preferable using five.variable rather than five.field. Many thanks, it unlocks me for my next works.
That’s great news, I’m glad you’re underway again!
Kind regards,
Jo