I have added a topic regarding the Update request payload before and it got solved real quick.
Now i have a doubt regarding the Initial Request payload and the initial request query.
If I use the data source option I am able to display the values in the database to the grafana element (Multi select with Custom options).
But the issue with that is if the query doesnt return any values and if try to switch values to show different values the old values will be there.Ideally if no values are present i the database the Multi select with Custom options should show 'choose'.
So i am trying to use the custom code option.
I have set Initial Action as Query and in the Custom Code section i have added
console.log(context.panel.data, context.panel.response, context.panel.initial, context.panel.elements);
return;
/**
* Data Source
* Requires form elements to be defined
*/
const dataQuery = context.utils.toDataQueryResponse(context.panel.response);
console.log(dataQuery);
context.panel.elements.forEach((element) => {
if (element.id === 'car') {
element.value = dataQuery.data[0]?.fields[1]?.values || [];
}
console.log("Field data: ", dataQuery.data[0]?.fields);
});
Is this the right way to use query for displaying initial values? if not please help !!