Performing query operation in MSSQL via Button Panel

Hello everyone. I’m currently in need of the user clicking or interacting with a panel and then it performs a query in the database (in this case, a MSSQL). There are a couple of posts regarding this action, however, none of them explain what exactly should be put on the “JSON Query” that is needed. I have the rawSql here (it’s actually a Procedure), but if I put, like suggested somewhere else, {“datasource”: , “rawSql”: } it gets me an error “404 Datasource not found” which is clearly an error since all the other query operations in the dashboard work normally.
I am now open to HTML button, however, I doubt that it will be easier to query via the HTML button than the Grafana Button panel.
Must I remind you that it is NOT an API call - it should be an operation directly to the database.
Any ideas?

just to understand, you want to click a button, and this button will connect to the database and execute a stored procedure?

Checkout this data manipulation plugin

1 Like

Kind of. It’s not an stored procedure, in regards that it’s not stored.
It looks like this:
USE
DECLARE
IF
BEGIN
EXEC etc
END

SELECT

Good morning yosiasz. Thank you very much for the reply. I’m currently studying the plugin, but I’m sure it’ll prove itself to be useful.
I’ll not mark your answer as the solution yet, as I’m hoping for a native solution for grafana. Seems like the button panel would be the most obvious approach.

EDIT 09/04 10:23 UTC-3: Yosiasz’s answer worked perfectly. For clarification purposes, I used the Data Manipulation Panel, put the Layout as Buttons only, disabled the Initial Request, and configured the Update Request to be Enabled if Changed. The update action is Data Source, and the Update Request Payload looks like this.

return {
rawSql: ‘UPDATE [].[dbo].[] SET = + 1’,
format: ‘table’,
};
This worked perfectly.

An additional modification I made is in the Custom Code to execute after update request:
if (response && response.ok) {

context.grafana.refresh();

} else {

}
Got rid of the notifications.

1 Like