Toolbox - Javascript to Bubble issue

Hello bubblers,

I am building an app that gets the data from an API into a RG. The data I am getting is a zip which contains 2 xml files. I am using a JS script to open the zip and read the content and using the “JS to Bubble” element from the Toolbox plugin to capture the content of the file and save it to my db.

Everything works smoothly except for the “JS to Bubble” which for some reason is capturing the data only on the last row of my RG.

Here is my JS script calling the bubble_fn function

async function fetchAndReadZip(url) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(‘Network response was not ok’);
}

    const blob = await response.blob();
    const zip = await JSZip.loadAsync(blob);

    let numberFileContent = null;

    // Regular expression to match files named with numbers followed by .xml
    const numberFilePattern = /^\d+\.xml$/;

    // Log all files in the ZIP for debugging
    console.log("Files in ZIP:");
    zip.forEach((relativePath, zipEntry) => {
        console.log("File:", relativePath);
    });

    await zip.forEach(async (relativePath, zipEntry) => {
        if (!zipEntry.dir) {
            console.log("Checking file:", relativePath);
            if (numberFilePattern.test(relativePath)) {
                const content = await zipEntry.async('string');
                console.log('Found number XML file:', relativePath, 'Content:', content);
                numberFileContent = content;

                // Call the function to send the content to Bubble
                bubble_fn_saveNumberXml(numberFileContent);
            }
        }
    });

    // Check if a number XML file was found
    if (!numberFileContent) {
        console.warn('Number XML file not found in the ZIP');
        bubble_fn_saveNumberXmlError('Number XML file not found in the ZIP');
    }

} catch (error) {
    console.error('Error opening ZIP file:', error);
    bubble_fn_saveNumberXmlError(error.message);
}

}

// Function to handle the number XML content
function bubble_fn_saveNumberXml(content) {
// Replace bubble_fn_saveNumberXml with bubble_fn_saveNumberXml (Bubble expects a specific format)
bubble_fn_saveNumberXml_(content); // Call the “JS to Bubble” function with the content
}

// Function to handle errors
function bubble_fn_saveNumberXmlError(errorMessage) {
// Replace bubble_fn_saveNumberXmlError with bubble_fn_saveNumberXmlError (Bubble expects a specific format)
bubble_fn_saveNumberXmlError_(errorMessage); // Call the “JS to Bubble” function with the error message
}

// Replace this with your actual URL
const url = 'Result of Step1 (Create a New invoice…)‘s URL’;
fetchAndReadZip(url);

Did any of you encountered this or a similar issue? How did you solved it?

maybe @mishav can help?

This topic was automatically closed after 70 days. New replies are no longer allowed.