Hi Folks, I can’t seem to figure out why I can’t get this update to work. I’m just trying to update an existing item. I’m not getting any errors in the console so I have no clue what’s up. I’ve tried it a few ways but my current code is below. Thanks in advance.
$w.onReady( function () {
$w( “#bugs” ).onReady(() => {
$w( “#submit” ).onClick((event) => {
var pic_source = local.getItem( “pic_source” );
const title = $w( ‘#newTitle’ ).value;
const reporter_name = $w( ‘#reporterName’ ).value;
const reporter_best_contact = $w( ‘#best’ ).value;
const tech_name = $w( ‘#tech’ ).value;
const browser = $w( ‘#browserBox’ ).value;
const msc_section = $w( ‘#mscbox’ ).value;
const operating_system = $w( ‘#opBox’ ).value;
const status = $w( ‘#status’ ).value;
const screenshot = pic_source;
const steps_to_produce = $w( ‘#reproduce’ ).value;
const expected_results = $w( ‘#expResult’ ).value;
const actual_results = $w( ‘#actResults’ ).value;
const notes = $w( ‘#notes’ ).value;
wixData.update( 'bug_reports' , { title, reporter_name, reporter_best_contact, tech_name, browser, msc_section, operating_system, status, screenshot, steps_to_produce, expected_results, actual_results, notes })
$w( '#ediBox' ).hide()
});
})
});
The update will work, if you have setted up all values right.
To update something, there has to be already some values in the database.
Take also a closer look at this…
The Promise is rejected if the current user does not have update permissions for the collection.
That means —> check DATABASE-PERMISSIONS (set all to everyone) and give full access to test your code.
Also do not forget to SYNC your DATABASE.
You will find all informations here…
https://www.wix.com/corvid/reference/wix-data/update
Permissions are set to anyone for all. Each column has a value for the current record as well. My code is accounting for all columns in the collection. The dataset is Read&Write and only showing one record. I’m not sure what you mean by SYNC your DATABASE. If you mean live vs. sandbox I’m only working in sandbox right now.
Try something like this…
import wixData from 'wix-data';
$w(function).onReady(() => {
$w("#submit").onClick((event) => {xxxxx(), $w('#ediBox').hide()})
})
function xxxxx() {
var pic_source = local.getItem("pic_source");
// const title = $w('#newTitle').value;
// const reporter_name = $w('#reporterName').value;
// const reporter_best_contact = $w('#best').value;
// const tech_name = $w('#tech').value;
// const browser = $w('#browserBox').value;
// const msc_section = $w('#mscbox').value;
// const operating_system = $w('#opBox').value;
// const status = $w('#status').value;
// const screenshot = pic_source;
// const steps_to_produce = $w('#reproduce').value;
// const expected_results = $w('#expResult').value;
// const actual_results = $w('#actResults').value;
// const notes = $w('#notes').value;
let toUpdate = {
"_id": "00001", // <--------- ??????
//-------------------------------------------------
"title": $w('#newTitle').value,
"reporter_name": $w('#reporterName').value,
"reporter_best_contact": $w('#best').value,
"tech_name": $w('#tech').value,
"browser": $w('#browserBox').value,
"msc_section": $w('#mscbox').value,
"operating_system": $w('#opBox').value
"status": $w('#status').value;
};
wixData.update("bug_reports", toUpdate)
.then( (results) => {
let item = results;
console.log(results)
} )
.catch( (err) => {
let errorMsg = err;
} );
}
Got it working. Thanks for the help.