Transferring data into another database after search

Hello Everybody,
I have got two databases among which are “Bookingdetails”, and “PastCustomers”. Booking details database is where all the recent booking are stored, and I would like to move that particular row of data into another database " Pastcustomers" upon button click. I have made a search bar to retrieve the guest booking information (which is working perfectly), but quite couldn’t figure out how to select that row or move that data into another database. Any help will be highly appreciated.

Thank you in advance!
Cheers

Once I click retrieve button, I am getting the results as expected, and the move button also lies inside the repeater. I should be able to insert data into another database with that “move button”…

//importing all the local files
import {local} from ‘wix-storage’;
import { pdf } from ‘backend/pdf.jsw’;
import wixData from ‘wix-data’;

//Start of Customers booking management Center
//to have search results
$w.onReady( function () {
$w(“#dataset1”).refresh();
var sameWord = local.getItem(“searchWord”);
$w(“#searchBar”).value = sameWord;
$w(‘#dataset1’).onReady( function () {
search();
});
});

function search() {
wixData.query(‘Bookingdetails’)
.eq(‘title’, $w(“#searchBar”).value)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
$w(‘#repeater11’).data = res.items;
$w(‘#repeater12’).data = res.items;
$w(“#image46”).hide();
});

}

export function searchButton_click(event) {
search();
$w(“#image46”).show();
$w(‘#columnStrip21’).expand();
$w(‘#repeater1’).expand();
$w(‘#repeater11’).expand();
$w(‘#repeater12’).expand();
}

**USING THIS UPTO HERE TO FIND THE RESPECTIVE INFORMATION OF GUEST AND IS WORKING PERFECTLY

**NOW I WOULD LIKE TO MOVE THAT PARTICULAR DISPLAYED RESULTS (LIES WITHIN THE SAME ROW OF “BOOKINGDATABASE”, INTO THE NEW DATABASE CALLED “PASTCUSTOMERS” USING BUTTON

export function movebutton_click(event) {

   wixData.query('Bookingdetails') 
    .eq('title', $w("#searchBar").value) 
  .find() 
   .then(res => { 

$w(‘#repeater1’).data = res.items;
$w(‘#repeater11’).data = res.items;
$w(‘#repeater12’).data = res.items;
$w(“#image46”).hide();

   }) 

   search(); 

let toinsert = search.items;
//Add your code for this event here:

wixData.insert("pastcustomers", toinsert) //inserts the item 
.then( (results) => { 

let items = results;
console.log(“done adding item”)
} )
. catch ( (err) => {
let errorMsg = err;
} );
}

You can see how to properly handle buttons in a repeater in this example.

Input Components in Repeater

Use input components in a repeater, and apply inline and global actions to repeater content.

Hi Yisrael,

Thank you for the prompt response.

I went through the editor window and codes, and found that you are working with two database collection for both pages, and there exits the interaction between them. I am not sure if that the one I was actually looking for. In short, I am just wondering to move specific row of data from one database to another database.

I have played with this code too, but it just moved the very first row of data irrespective of what I am getting after the search result.

export function movebutton_onClick(event, $w) {
	let toInsert = $w("#dataset1").getCurrentItem(); //gets the current item
	wixData.insert("pastcustomers", toInsert) //inserts the item
	.then( (results) => {
		console.log("done adding item")
	} )
	.catch( (err) => {
		let errorMsg = err;
	} );
}

The datasets don’t matter so much. What matters is that you need to use the repeated-item-scope selector . You are currently using the global context selector ($w) which is the reason you are getting the same row every time.

Hi Yisrael,

Thank you so much for your help! I got the result as I have wanted. Just in case, someone reach to this post with same type of issue, I have attached the code that worked for me here-under.

Thank you once again!!

export function movebutton_click(event) {
let $item = $w.at(event.context);
let clickedItemData = $item(“#dataset1”).getCurrentItem();
let toInsert = clickedItemData //gets the current item
wixData.insert(“pastcustomers”, toInsert) //inserts the item
.then( (results) => {
console.log(“done adding item”)
} )
. catch ( (err) => {
let errorMsg = err;
} );

}