How do i send multiple data items from the recives message block for webviewer extension

I’m currently working on a project where I use the Thunkable WebViewer Extension to communicate between my Thunkable app and a web page. I have successfully sent and received messages, but I’m facing a challenge when trying to send and receive multiple data items.

In my web app, I’m sending an object with several properties using the ThunkableWebviewerExtension.postMessage function. However, on the Thunkable side, when I receive the message in the “When WebViewer receives message” block, I’m struggling to access and display each individual property.

Here’s a simplified version of my current setup:

fetch(‘/run_script’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
username,
password
})
})
.then(response => response.json())
.then(data => {

                const outputArray = data.output;

                // Display each element separately
                document.getElementById('result').innerText =
                    `Smart Schedule Sync Complete. 
                    Token: ${outputArray[0]},
                    Username: ${outputArray[1]},
                    Cookies: ${outputArray[3]}`;

                ThunkableWebviewerExtension.postMessage(outputArray[0]);
                ThunkableWebviewerExtension.postMessage(outputArray[1]);
                

                    
            })
            .catch(error => {
                document.getElementById('result').innerText = "Error: " + error;
            })
            .finally(() => {
                loadingScreen.style.display = 'none';
                runScriptButton.disabled = false;
            });
    });

in thunkable it only shows the first data item ThunkableWebviewerExtension.postMessage(outputArray[0]);
and also sets my other label that i have on thunkable to ThunkableWebviewerExtension.postMessage(outputArray[0]);

Probably getting called too quick.

I would pass back the array of two items and parse it in the app

Hi @mubariz_saeedthg, welcome to Thunkable! :tada:

Remember to check out our Community Guidelines and How to ask Great Questions v2.0 posts for tips on getting the best support from the Community on your issues.

I need to send:
Token: ${outputArray[0]},Username: ${outputArray[1]}, Password: ${outputArray[2]}

however when I try to send a post message from thunkable it only sends one message and if i needed to send all 3 i would just need one VERY long string variable

What’s the issue with this :point_up_2:

Post the object back to your app, dude. That’s what you’ll do here

How would i do that exactly can u explain? with an example please?

"What’s the issue with this :point_up_2:

Post the object back to your app, dude. That’s what you’ll do here"

whenever i try to parse in the app it just duplicates the first one it doesent give me two unique values

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.