Transfer data from one data set to another.

Hi,
I am trying to get data from a dataset of members and collect the email id, and then insert the email id in a new dataset “#dataset1”. I am new to java script and am self taught that’s why not getting where i am wrong.
Any help is greatly appreciated. I am posting the end part of the code where I feel I am stuck. I can provide more details if need be.

The is the code -
export function button1_click(event) {
//Add your code for this event here:
$w(“#teamDataset”).onReady(() => {
const currentItem1 = $w(“#teamDataset”).getCurrentItem();
if (user.loggedIn) {
user.getEmail().then(email => {
wixData.query(“Members1”).eq(‘email’, email).find()
.then(result => { //don’t know what result is

    **let**  userEmail = user.getEmail();      //  ["user@something.com"]("user@something.com"

l)

let item = result.items[0]; //don’t know what this item is and how to use
wixData.insert(“dataset1”, {
‘title’: userEmail
});
$w(‘#dataset1’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
} );
$w(‘#teamDataset’).setFieldValues({
‘rateNumber’: newRate
});
$w(‘#teamDataset’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
} else { wixWindow.openLightbox(“login”) }
});
}

Hello.

‘result’ is an array of items while result.items[0] is a reference to the first element in the result array. You can see the contents of the result.items[0] by using console logs. To learn more click here .

Assuming “Members1” collection has an email field with ‘emailId’ as its field key, you can access the email from the results call back as shown below:

let item = result.items[0];
let userEmail= item.emailId;

Please note that insert method cannot be applied to a dataset but only to a database collection as shown here.

Please do the necessary adjustments to your code.

Good luck!

1 Like

“Please note that insert method cannot be applied to a dataset but only to a database collection as shown here .”
This statement helped me a lot. I figured it out. Well i’m not understanding the array part. But atleast now i’m able to insert the user email in my desire collection.
Thanks a lot.

Danzong