Struggling with business forms plugin from version 4.1.0 on

I am using bussines froms plugin version 4.2.0
I have in the playload simple test:

const payload = {};

// Adiciona elementos ao payload se tiverem valor
context.panel.elements.forEach((element) => {
if (!element.value) {
return;
}

payload[element.id] = element.value;
});

// Adicionando valores fictícios ao payload
payload.values = [
[‘John’, ‘Doe’, ‘john.doe@example.com’, ‘USA’, ‘New York’, ‘Company A’, ‘Unit 1’, ‘Campaign 1’, ‘Course 1’, ‘Module 1’, ‘Module 2’, ‘In Progress’, ‘Not Started’],
[‘Jane’, ‘Smith’, ‘jane.smith@example.com’, ‘Canada’, ‘Toronto’, ‘Company B’, ‘Unit 2’, ‘Campaign 2’, ‘Course 2’, ‘Module 3’, ‘Module 4’, ‘Completed’, ‘Not Started’]
];

// Log do payload final para depuração
console.log(payload);
return payload;

in Query I have one replace
REPLACE INTO training.table (
First Name,
Last Name,
Email,
Country,
City,
Company,
Unit,
Campagin,
Course,
Enrolled Module,
Completed Module,
In Progress,
Not started
) VALUES ( ${payload} );

it is not working,
Please someone could help me !!!
My necessity is to upload csv file direct into a mysql table, but even this simple example is not working. HELPpppppppp

The custom code is
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.’]);
}

can you expound on the above? are you seeing an error?

I am getting
Update

Values updated successfully.

but nothing replaced into the table

so the update is working. what seems to not be working is the subsequent data fetch. are you doing a re-query of the target table after this update to repopulate the table?

const payload = {};

context.panel.elements.forEach((element) => {
if (!element.value) {
return;
}

payload[element.id] = element.value;
});

const readCSV = (file) =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsText(file);
reader.onload = () => {
const csv = reader.result;
const rows = csv.split(‘\n’).filter(row => row.trim() !== ‘’);

  const delimiter = csv.includes(';') ? ';' : ','; // Detect delimiter

  const data = rows.map(row => {
    const [item, valor] = row.split(delimiter);
    return { item: item.trim(), valor: valor.trim() };
  });

  resolve(data);
};
reader.onerror = reject;

});

/**

  • Data Source payload
    */
    const getPayload = async () => {
    const file = payload.file[0];
    const csvData = await readCSV(file);

// Filter only for “CAPACIDADE” and “OBSOLETO”
const filteredData = csvData.filter(row =>
row.item === ‘CAPACIDADE’ || row.item === ‘OBSOLETO’
);

const values = filteredData.map(row => ('${row.item}', '${row.valor}')).join(‘,\n’);

return {
rawSql: REPLACE INTO sala_tinta.capacidade (Item, valor) VALUES ${values};,
format: “table”,
};
};

return getPayload();

that code worked fine until bussines forms version 3.8, but from 4.0 on version is not longer working …

1 Like

yes I added the truncate on reset button , and the replace on update button

another exemple on reset
return {
rawSql: ‘TRUNCATE TABLE sala_tinta.est_max_tinta’,
format: ‘table’,
}

update
const payload = {};

context.panel.elements.forEach((element) => {
if (!element.value) {
return;
}

payload[element.id] = element.value;
});

const readCSV = (file) =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsText(file);
reader.onload = () => {
const csv = reader.result;
const rows = csv.split(‘\n’).filter(row => row.trim() !== ‘’);

  // Check if the file starts with "sep="
  const startWithSep = rows[0].startsWith('sep=');

  // If it starts with "sep=", skip the first two lines, otherwise skip the first line
  const dataRows = startWithSep ? rows.slice(2) : rows.slice(1);

  const delimiter = csv.includes(',') ? ',' : ';'; // Detect delimiter

  const data = dataRows.map(row => {
    const [item, valor] = row.split(delimiter);
    return { item: item.trim(), valor: valor.trim() };
  });

  resolve(data);
};
reader.onerror = reject;

});

/**

  • Data Source payload
    */
    const getPayload = async () => {
    const file = payload.file[0];
    const csvData = await readCSV(file);

const values = csvData.map(row => ('${row.item}', '${row.valor}')).join(‘,\n’);

return {
rawSql: REPLACE INTO sala_tinta.est_max_tinta (Material, \Qtd Lata`)
VALUES ${values};`,
format: “table”,
};
};

return getPayload();

working fine busines forms 3.8 version
not working newer versions




reset is fine !
the upload works on version busines froms 3.8


data there again!!!

same dashboard is not working on business forms 4.X
this is my problem

1 Like

do you see any errors in browser console?

i would post in that plugins github repo