Updating a Init Value of a Variable with another Query

i am little bit confused how i can update a variable in a simple way which is already binded to a logic or query.

Let me explain you, please (just remember that everything is a basic approach):

  • I have a Dropzone where i upload file(s) and show the uploaded files in a table.

  • To retrieve the metas from the files i use following query:
function getFileMetadataAndData() {
  const files = fileDrop.value || [];
  const fileResults = files.map(file => ({
    name: file.name,
    type: file.type,
    sizeBytes: file.sizeBytes,
    base64Data: file.base64Data,
    dataURL: `data:${file.type};base64,${file.base64Data}`
  const blobResults = files.map(file => new Blob([file.base64Data], { type: file.type }));

  return { fileResults};

return getFileMetadataAndData();

  • After retrieving the files, lets say, i want to delete one file, which is in this case "1.webp". For that one i have another query, which is comparing the selected files from the table and the uploaded files. It will return me the difference to "filesForUpload"
return ((selectedFilesTable !== null) ? (() => {
    const fileMetadata = getFileMetadataAndData.data.fileResults;
    const filteredFiles = fileMetadata.filter(file => !selectedFilesTable.value.some(selectedFile => selectedFile.name === file.name));
    getFileMetadataAndData.data.fileResults = filteredFiles;
    return filteredFiles;
  })() : getFileMetadataAndData.data.fileResults);

Basically ("getFileMetadataAndData" - "selectedFilesTable")

  • Now i am using "filesForUpload" to display the table, so as i said i will delete 1.webp

    Its working.

But my problem is, that i am getting the variable "filesForUpload" is binded to the output of the query "getFileMetadataAndData"

I really need to update this variable "filesForUpload", without always retrieving from "getFileMetadataAndData" otherwise i will basically delete one file in the variable, but if i delete seperately another one, the first deleted will appear again. :smiley: . Like a never ending loop.

Is there a way to override the variable "filesForUpload", to not be binded anymore after i made the second query which is "deleteLogicTable" ?

You dont need to understand my logic i built fully, it is something i need. Just how to override the binded variable with another value.

Hi @allinjoe,

I appreciate you saying not to need to fully understand the logic! I think you should be able to achieve what you want by editing the getFileMetadataAndData function to exclude anything in the deleteLogicTable. Maybe a filter before returning the value, so anything that is flagged to be deleted is removed from the data before it's returned to the table - would that work?

Hi @MikeCB, thanks.

i see that i forgot to mention that the query getFileMetadataAndData will be changed anyway to a basic FileReader(), which means i need to save all further steps into variables that i can override.
In retool i only can bind the variable to a result, that’s what i understood.
e.g. {{somesource.data.moredata}}

What i need is to have an init value like {{somesource.data.moredata}} and override it from another query.

not sure if that is possible.

However, still many thanks. :smiling_face:

Hi @allinjoe,

Yes, you can bind it to a result, but that result can be JS code that returns the values you need. You could try doing something like:

Create a new JS Query and call it something like accurateData

const fileReaderDataFn = () => {
  // Do whatever you need to generate your default data

const deletedDataFn = () => {
  // Pull in the data from wherever you're storing deleted data from, or whatever logic would provide you with the data you want after you've deleted something

// This could be cleaned up, but for the sake of easy-reading...
const deletedData = deletedDataFn()
const fileReaderData = fileReaderDataFn()

if(deletedData) return deletedData // adjust depending on what it means when this data is what should be use... array length > 0 probably?
return fileReaderData // If it hasn't returned data that's been manipulated, just return the original data

I guess we are coming closer with the understanding. :blush:

But this approach sounds very good, thanks.
I will try it and let you know. :+1: