Having trouble getting my api query result into localstorage

I have an api query that runs successfully and returns a JSON Object.

I then have a transformer1 that maps the records from the object like this:

let finalData = {{apiQuery.data.records.map(records => records.fields)}};

return finalData;

I want to put this return into local storage.

I try this:

let finalData = {{apiQuery.data.records.map(records => records.fields)}};
return finalData;

But I get 'function run failed' error.

If I setup a second query to run JS with the following code I can get the data into localStorage. What is my admittedly somewhat beginner brain missing?

function storeDataInLocalStorage() {
    const data = transformer1.value;

return storeDataInLocalStorage();

Thanks for any thoughts.


EDIT - Just noticed its an API query, create a separate query and run the secondary on success of the first. - EDIT

transformers constantly run, you cant set temp states inside of them.

Just add the mapping you have in the transformer into the query and even set localstorage in the same query.

let finalData = {{apiQuery.data.records.map(records => records.fields)}};
localStorage.setValue('insertedHere', finalData)
1 Like

Got ya, it was the transformers constantly running. Thanks! I was partly trying to understand why it was failing there but working if I spun up another query, and that explains it.