Update record by block that use external data

Hi,

I am prototyping Softr as a potential platform for displaying our event data. However, I am facing an issue.

I created a chart block and tested if it’s possible to mutate or do my own calculations to the data before it gets displayed. I read the documentation and there was an option to listen to an event

window.addEventListener('get-records-table1', onRecords);

I’ve checked the hrid of the block and it was chart1 so updated the event to

window.addEventListener('get-records-chart1', onRecords);

And for unknown reasons, the event is never fired and cannot listen to it. Am I missing some sort of configuration?

PS: The source of the external data is currently a sheet and will be coming from a database in the future.

Hi @Yazan

Can you share with us where and how you register for the event ?

try adding into app or page settings head section custom code area… and

<script>
	
	const onRecords = (e) => {
		console.log(e)
	};
	
	window.addEventListener('get-records-chart1', onRecords);
	
</script>

–Artur

Hi @artur
That’s where I have the code initially in the page settings → Custom Code → inside header.
And when I check the console in the preview, I see nothing.
I can see that the script is being injected, but the event is never fired.

I also added the script in the custom code of general settings on the left side.
I feel like I am missing some sort of configuration to enable such behavior.

block-loaded-chart1 is working but not get records.

<script>
window.addEventListener('get-records-chart1', ()=> {
  console.log("GOT RECORDS")
}); // not loading
	
window.addEventListener('block-loaded-chart1', (e) => {
  console.log("BLOCK LOADED")
}); // is loading
</script>

Let’s close this topic. I will be using a custom REST API as a data source, which would solve the problem.