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

Unable to run a query with JSON in custom code payload #524

Open criticalboot opened 5 days ago

criticalboot commented 5 days ago

trying to insert geolocation as json into postgres with the following custom code.

payload = {"Number": 12345, "StationId": 1, "haltSeqNo": 13, "lat": 10, "long": 11} payload.alert = {"lat":${payload.lat},"long":${payload.long}}

INSERT INTO "Stations" ("Number", "stationId", "haltSeqNo", "alert") VALUES (${payload.Number}, ${payload.station}, ${payload.haltSeqNo}, '${payload.alert}')

Screenshot from 2024-10-17 22-19-38

mikhail-vl commented 5 days ago

@criticalboot You can check in the Browser's network activity, the query with replaced and not replaced variables.

Double check element's id, for example ${payload.station} should be ${payload. StationId} based on your payload. Thinking about it, we can update plugin to display the resulted query in the alert to help with troubleshooting.

criticalboot commented 5 days ago

@mikhail-vl It's a typo and has been fixed, but the issue remains.

tried to print the SQL in custom code with payload.sql = `INSERT INTO "Stations"("Number", "stationId", "haltSeqNo", "alert") VALUES (${payload.Number}, ${payload.station}, ${payload.haltSeqNo}, '${payload.alert}')`; console.log(payload); and got the desired result.

mikhail-vl commented 5 days ago

@criticalboot Print won't work, because replace variables happens on the data source level.

Check the query in the network activity for /ds/query.

criticalboot commented 5 days ago

@mikhail-vl No network activity was found for this query.