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);
}