Get wix data and put it into a new dataset

Hi,

I found this script to extract the name from a wix user dataset and display it in a text field. Now I want this name to be used in another dataset. This script I have shows the name but does not write it to the new dataset…

When I test it does the name also disappear when saving the data? How can I solve both of those?

This is the script I’m using now:

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

$w . onReady ( function () {

wixData . query ( "Members/PrivateMembersData" ) 
        . eq ( "_id" ,  wixUsers . currentUser . id ) 
        . find () 
        . then (( results ) => { 
           $w ( '#text10' ). text  =  results . items [ 0 ]. nickname ; 
        }) 

});

Dataset1↓


Dataset2↓

Mixing wix-data with datasets and setting inside of property-panel → IS NOT A GOOD IDEA! ! !

Either go the one way, or the other.

Mixing both always —> ends in issues!

And what exactly is a → DATASET ???
Did you ever ask yourself this question?

a) Is it something what can hold data inside?
b) Is it something what has the functionality of somekind of a → “data-wire” <— between your DATABASE and your elements on your page?
c) Can a dataset survive without a → DATABASE in the background?
d) Is it something you can eat?

So first try to understand the functionality of a dataset and then ask yourself your own question one more time…

Get wix data and put it into a new dataset
How to put data into a dataset? Is this possible? Where do the data go to?

When I test it does the name also disappear when saving the data? How can I solve both of those?
How do you start your saving process?
Do you have a code for the SAVE-ACTION?
Or did you just simply connected your button inside of propertypanel?

Hi,

Thanks for your reaction.

What i want is to use the name of the logged in person on another page when he has filled in the data.

I don’t know much about datasets and bases (sorry) :pray: hope someone could/will help me in an easy way.

Thanks

You should first make clear if you want to go the Wix-Data-way or if you want to use a DATASET. It always ends in issues and problems when you try to mix both, especialy when you do not really understand what you are doing.

When I test it does the name also disappear when saving the data? How can I solve both of those?

As you can see, your problems already begins here.

So let’s make clear, what exactly you want to achieve first.

  1. IDENTIFYING CURRENT LOGGED-IN-USER:
    wixUsers . currentUser . id
  2. You want to find data of this user out of the Private-Members-Data
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results) => {
    ................
}))

Let’s say it worked and you got your data.
3) You paste this gotten data-value into a n INPUTFIELD, which is connected through a dataset (let’s say → “dataset1”) to a database in the background.

$w('#text10').text = results.items[0].nickname;

We can see it here that this INPUTFIELD is connected…


… to a dataset (in this example it will be —> “dataset1”

  1. Now your wish will be, to save this found value(s) inside of your database, which is connected with(trough) “dataset1”.

But the problem is, that for sure your “SUBMIT-BUTTON” is also connected to the dataset inside of the PROPERTY-PANEL. And here your PROBLEM begins!

Maden connections trough the propertypanel, have their (i call it) own LIFE!
So if you press the SUBMIT/SAVE-BUTTON, nothing really happens, right?
Or at least something unexpected happens.

To make sure everything works the right way, you can either code it, or you can try to modify your SETUP as following…

  1. CHECK if your DATASET-SETTINGS are settep-up as “READ”
    This will make sure, that your inputfield will work and will accept the ID.

Now your ID should be visible inside of the INPUT-ELEMENT…


2) Make sure that your SUBMISSION-BUTTON, is connected to dataset and setted-up for SUBMISSION inside of the dataset-options…

This makes sure to start the saving process to the database which is connected to the dataset1.

Also you have to set up the right data-field where the data (inside of the PROPERTY-PANEL) of the INPUT-FIELD, will have to go to, like shown in the following expample…

In this case we selected DATAFIELD → “TITLE”

So what happens next ?

Let’s press the SUBMIT-BUTTON…


Now the data should go directly to our (in the background placed) database, by a click onto the SUBMIT-BUTTON… let’s have a look…into database…

Et, voilà!!!

The data is already inside of your DATABASE. In the → “Title-Field” like shown on the pic.

So what was the question now?

HOW TO DELETE THE VALUE INSIDE OF THE INPUT-ELEMENT AFTER SAVING-PROCESS???

Like this…

import wixUsers from 'wix-users';

$w.onReady(async function() {console.log("Dataset ready...");
    $w('#dataset1').onReady(async()=>{
        let currentUser = await wixUsers.currentUser.id; console.log(currentUser);
        $w('#input1').value = currentUser;
    });
});

HOW NOT TO DELETE THE VALUE INSIDE OF THE INPUT-ELEMENT AFTER SAVING-PROCESS???

Like this…

import wixUsers from 'wix-users';

$w.onReady(async function() {console.log("Dataset ready...");
    let currentUser = await wixUsers.currentUser.id; console.log(currentUser);
    $w('#input1').value = currentUser;
    
    $w('#dataset1').onReady(()=>{   
        //your further code here...
    });
});

Hi,

I solved it in another way. The user now has to perform 1 extra action, but the most important thing is that it works :slight_smile:

Thanks for your help