VolkovLabs / business-forms

The Business Forms panel is a conceptually new plugin for Grafana. It is the first plugin that allows inserting and updating application data, as well as modifying configuration directly from your Grafana dashboard.
https://docs.volkovlabs.io
Apache License 2.0
86 stars 10 forks source link

Issue with Updating PostgreSQL Table Using Business-Forms Panel #544

Closed m4v3rickmts closed 2 weeks ago

m4v3rickmts commented 2 weeks ago

Hi I am encountering an issue when trying to update a table in PostgreSQL through the Business-Forms panel, following the video tutorials. Here are the details:

I followed the example from the video, "Data Manipulation for Grafana | Use REST API, Data Source, and Queries to Manipulate Your Data." The PostgreSQL connection from the panel works without issues, and data can be queried successfully. The process goes smoothly until I reach the "Confirm Update Request" popup. At this point, all the values appear correctly, and everything looks fine. However, after confirming, the data does not update in the PostgreSQL database. No info in the browser developer tools.

Troubleshooting Steps Taken: I tested a direct UPDATE statement on this table using the grafana dashboard's variable for PostgreSQL, and it executed successfully, confirming that: The business forms panel can retrieve data from PostgreSQL. The user has the necessary permissions, as an UPDATE statement from the dashboard works as expected. Additionally, I tried modifying the return {} part by replacing rawSql: with a hardcoded UPDATE statement, but this also failed to produce any updates in the database.

Would appreciate any insights or guidance on getting the Business-Forms panel to perform the update operation as expected. Thank you!

mikhail-vl commented 2 weeks ago

@m4v3rickmts Do you use the latest 4.8.0 version of the Business Forms ? We added displaying Data Source request error in the alert message to help troubleshoot issues.

I would recommend to update the version. Alternatively, you can check the network activity /ds/query in the browser to find the error in the data source response.

m4v3rickmts commented 2 weeks ago

@mikhail-vl Thanks for your reply. We are using the latest version (4.8.0). I will try to check the network activity today. Thanks for the hint.

It seems like the rawSql is empty. I will investigate this further.

mikhail-vl commented 1 week ago

@m4v3rickmts rawSQL comes from the Query Editor for the request.

It should be easier to troubleshoot in 4.8.0, it helped me on Friday to find my issues.

m4v3rickmts commented 1 week ago

@mikhail-vl I had to switch back to "return payload;" in the "Create Payload" section. The rawSQL in the return statement, as provided in the video tutorial, didn't work for me, but using "return payload" and the update statement in the "Query Editor" works.

Only thing now is that I have to manually refresh the page to see the updates values.

I use in "Custom Code" the "Query"-Action with the standard code.

Shouldn't "context.grafana.locationService.reload();" refresh the fields and show the updated values?

m4v3rickmts commented 1 week ago

Got it working. I had to change the "Custom Code" inside the "Update Request".

This didn't work for me:

if (context.panel.response) {
   context.grafana.notifySuccess(['Update', 'Values updated successfully.']);
   context.grafana.locationService.reload();
} else {
   context.grafana.notifyError(['Update', 'An error occurred updating values.']);
}

That worked:

if (context.panel.response) {
  context.grafana.notifySuccess(["Update", "Values updated successfully."]);
  context.grafana.refresh();
} else {
  context.grafana.notifyError([
    "Update",
    `An error occurred updating values: ${context.panel.response.status}`,
  ]);
}

Thanks for your support!

mikhail-vl commented 1 week ago

@m4v3rickmts Are you using Grafana 11.3 with Scenes dashboards enabled?

Grafana introduced breaking changes with refreshing dashboards which explains difference between context.grafana.locationService.reload and context.grafana.refresh.

m4v3rickmts commented 1 week ago

@mikhail-vl , we are using Grafana v11.1.0 on our DEV environment.