Hello everyone, I’m having a problem in updating a record in the database where a person press the update button and it should update the record. However, all the methods that have been mentioned below does not update the record. What could be the error/issue?
Please find below the code for updating the record:
let IDQuery = wixData.query("AttendeeDB").eq("attendeeId",userID);
let userID = session.getItem('transID'); //Where result will be a string.
export function button1_click(event) {
//Add your code for this event here:
let toSave = {
"title": $w('#Title').value,
"firstName": $w('#FirstName').value,
"lastName": $w('#LastName').value,
"phoneNumber": $w('#PhoneNumber').value,
"occupation": $w('#Occupation').value,
"specialty": $w('#Specialty').value,
"email": $w('#Email').value,
"password": $w('#Password1').value
};
//Method1:
wixData.save("AttendeeDB", toSave).then((results) =>
{
let item = results; //see item below
}).catch((err) =>
{
let errorMsg = err;
});
//Method2:
wixData.query("AttendeeDB").eq("attendeeId",userID).find().then((results) =>
{
let item = results.items[0];
let resultCount = results.totalCount;
item.title = $w('#Title').value;
item.firstName = $w('#FirstName').value;
item.lastName = $w('#LastName').value;
item.phoneNumber = $w('#PhoneNumber').value;
item.occupation = $w('#Occupation').value;
item.specialty = $w('#Specialty').value;
item.email = $w('#Email').value;
item.password = $w('#Password1').value;
wixData.update("AttendeeDB", item);
}).catch((err) =>
{
let errorMsg = err;
});
// Method 3:
$w("#dataset1").setFilter(IDQuery).then(() =>
{
$w("#dataset1").setFieldValues({
"title": $w('#Title').value,
"firstName": $w('#FirstName').value,
"lastName": $w('#LastName').value,
"phoneNumber": $w('#PhoneNumber').value,
"occupation": $w('#Occupation').value,
"specialty": $w('#Specialty').value,
"email": $w('#Email').value,
"password": $w('#Password1').value
})
}).catch((err) =>
{
let errorMsg = err;
});
$w("#text19").show();
$w("#text19").text = "Information has been updated";
setTimeout(wixLocation.to(`/mainpage`), 2000)
}
#updatedatabase #updaterecord