Moving data from one collection to another

I have product reviews I made using Wix code. When a user submits a review it goes into an approval dataset which is displayed on a page in the site. An admin would then go on that page and approve or decline the review.

Im having a problem with it on the live site. In the editor, my code works fine and the review is moved from one dataset to the other. In the live site, nothing happens. Below is the code. Im hoping someone can tell me what is wrong with it so I can get it up and running. The code below is in the $w.onReady( function () {

$w('#approveButton').onClick(() => {
let toInsert = $w("#pendingReviews").getCurrentItem(); //gets the current review
let toDelete = toInsert._id
console.log(toInsert)
wixData.insert("reviews", toInsert) //inserts the review into the live reviews dataset
.then(() => {
wixData.remove("reviews-under-approval", toDelete) //deletes the review from the under approval dataset
.then(() => {
$w("#successMessage").show("fade")
setTimeout(function () {
$w('#successMessage').hide("fade")
}, 2000)
})
})
.catch((err) => {
let errorMsg = err;
});
})

Hi Cody,

It could very well be a collection permissions issue. Alter those if it makes sense to do so, or you can override them with options, the third parameter of the insert and remove functions.

https://www.wix.com/corvid/reference/wix-data.html#insert
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions

Hey @tony-brunsman , I thought it was the same thing so I switched over the permissions to Anyone on all of them before posting this. For some reason it’s still not working.

@codydstevens7 The onClick code block also needs to be inside an onReady for the “#pendingReviews” dataset. The getCurrentItem function is likely returning nothing on the live site as it’s currently coded.

@tony-brunsman Its current in the $w.onReady( function (). I initially had it in its own Click function affiliated with the button but since that wasn’t working on the live, I tried to put it in there. The Decline button is in its own function (shown below) and it works flawless on both the editor and the live site.

If you want to test it go here

export function declineButton_click(event, $w) {
let getId = $w("#pendingReviews").getCurrentItem(); //gets the current item
let toDelete = getId._id
wixData.remove("reviews-under-approval", toDelete) //deletes the item
.then(() => {
$w("#declineMessage").show("fade")
setTimeout(function () {
$w('#declineMessage').hide("fade")
}, 2000)
})
.catch((err) => {
let errorMsg = err;
});
}


@codydstevens7 I wanted to make sure that the previous post was clear about the need for two onReadys: one for the page and one for the dataset like follows:

$w.onReady( () => {
  $w("#pendingReviews").onReady( () => {
    let toInsert = $w("#pendingReviews").getCurrentItem();
  } );
} );

@codydstevens7 @tony-brunsman I was just wondering if you solved this? If so could you please provide the full code?