Why its not submitting data in another database?

import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;

$w . onReady ( function () {

let user = wixUsers . currentUser ;
let userId = user . id ;
console . log ( userId )

wixData . query ( “Members/PrivateMembersData” )
. eq ( “_id” , wixUsers . currentUser . id )
. find ()
. then ( ( results ) => {
console . log ( results . items [ 0 ])
$w ( ‘#email’ ). value = results . items [ 0 ]. loginEmail ;
});

wixData . query ( “UsersAllDataset” )
. find ()
. then ( ( results ) => {
console . log ( results . items [ 0 ])
$w ( ‘#userTypeCode1’ ). value = results . items [ 0 ]. userCode ;
$w ( ‘#userType1’ ). value = results . items [ 0 ]. title ;
$w ( ‘#uniqueCode1’ ). value = results . items [ 0 ]. uniqueCode ;
});

});

The above code is working fine. I wanna take login email of wix member and its working + I wanna take some info from another dataset its also showing desired data in ‘input’… but after submitting data no data is showing in desired dataset.
Link is - https://onlinesanawad.editorx.io/mysite-2/products-posting
Kindly resolve this issue.

If this is your whole code, so where is the part with the SUBMISSION?

How doy ou SUBMIT? Show your PROJECT-SETUP, first.
You surely are using a DATASET , don’t you ?

Must know knowledge - → Mixing CODE and DATASET-SETUPS are not the best idea and also not recommended.

Since you are using Wix-Data you normaly do not need any DATASETS, because all can be done by code.

You will have to generate CODE, which will save all your DATA into your wished DATABSE.

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;

$w.onReady(function () {

let user = wixUsers.currentUser;
let userId = user.id;
console.log(userId)

wixData.query(“Members/PrivateMembersData”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then( (results) => {
console.log(results.items[0])
$w(‘#input7’).value = results.items[0].loginEmail;
$w(‘#input5’).value = results.items[0].firstName;
$w(‘#input6’).value = results.items[0].lastName;
});
} );

export function button1_onClick() {
$w(‘#dataset1’).setFieldValue(‘firstName’, $w(‘#input5’).value);
$w(‘#dataset1’).setFieldValue(‘lastName’, $w(‘#input6’).value);
$w(‘#dataset1’).setFieldValue(‘eMail’, $w(‘#input7’).value);
}

The export function part isn’t working. What do I do wrong? Thank you!

Hi, @russian-dima , Thanks for quick response. I have provided the link above and just below a sample code where question is same… Why it is now taking any data into another database?
https://onlinesanawad.editorx.io/mysite-2/products-posting
This is my site link where you can register simply and can go to product posting page. Your info like email and other info is prefilling successfully but after submission through ‘Submit’ Button which is connected, the final desired dataset of ‘Products’ not taking the prefilled input information/data. Thanks in advance.

Try this one…

import wixUsers from 'wix-users';
import wixData from 'wix-data';

$w.onReady(function () {
    let user = wixUsers.currentUser;
    let userId = user.id; console.log(userId);

    wixData.query("Members/PrivateMembersData")
    .eq("_id", wixUsers.currentUser.id)
    .find()
    .then((results) => {console.log(results.items[0])
        $w('#input7').value = results.items[0].loginEmail;
        $w('#input5').value = results.items[0].firstName;
        $w('#input6').value = results.items[0].lastName;
    });

    $w('#button1').onClick(()=>{
        $w('#dataset1').setFieldValue('firstName', $w('#input5').value);
        $w('#dataset1').setFieldValue('lastName', $w('#input6').value);
        $w('#dataset1').setFieldValue('eMail', $w('#input7').value);
    });

    $w('#dataset1').onReady(()=>{
        $w('#dataset1').save()
        .then((item)=>{let fieldValue = item.fieldName; console.log(fieldValue);})
        .catch((err)=>{console.log(err);});
    });
});

EDIT: You perhaps also should consider to use → setFieldValues instead, which gives you the ability to set multiple values and save them at once…

$w("#myDataset").setFieldValues({
   'firstName', $w('#input5').value,
   'lastName', $w('#input6').value,
   'eMail', $w('#input7').value
});

@russian-dima Thanks : ) alot man… This code is working superbly… Bingo… : )
Thanks… Thanks… Thanks : )

@onlinesanawad
No problem!