Hey, so I have two datasets: 1) Client Addresses and 2) Deliveries Dataset
In the Client Addresses dataset, my clients can enter their details, save and update that saved information whenever they want.
On a separate page, I want to pull the data entered in Client Addresses and display it in input boxes (sort of like an autofill situation) and then when they press submit, that it saves to the deliveries data set. I have no idea how to do that.
I’ve tried the Get function, the Query function and the getCurrentitem function. The only one that actually autofilled the data was the Get function. The only problem with that is, I can’t pull data from the Client Addresses dataset with the item ID cause I don’t know what the item ID will be for future users and the item ID is automatically set…
Please help me, i’ve been on this for two months.
Hi there,
You don’t need to know the item _id of the addresses database, you just query it, try to query the addresses databse with the _owner field instead, and use the user ID for it.
wixData.query('colName'),eq('_owner', wixUsers.currentUser.id).find()
.then((x) => {
if (x.length > 0) {
const [firstItem, secondItem] = x.items;
}
})
Then use the items above toautofill the fields.
$w('#street').value = firstItem.street;
$w('#city').value = firstItem.city;
And before submitting,
A) If you’re using a dataset:
$w('#dataset').onBeforeSave(() => {
$w('#dataset').setFieldValues({
street: $w('#street').value,
city: $w('#city').value
})
})
B) If you’re using Wix Data
const request = {
field1: input1,
field2: input2,
street: $w('#street').value,
city: $w('#city').value
}
wixData.insert('colName2', request);
Hope this helps~!
Ahmad
You’re welcome … Happy to help