Transferring information pulled from one database and displayed in a field. Into another database

I have seen a few posts asking similar questions so I believe this would be useful to the community.

I am trying to take the information displayed in a field, pulled from one database. And transfer that information into another database using an OnClick event.

The Database displaying the information is called ‘JobListings’ and displays the job title in #text1 on the page. I am trying to move the text in #text1 to a database called ‘Applicants’

This is my existing code and I am having no luck with it at all! Can anyone help??

import wixData from ‘wix-data’;
export function button6_Click(event, $w) {
let toInsert = $w(“#text1”).getCurrentItem(); //gets the current item
wixData.insert(“Applicants”, toInsert) //inserts the item
.then( (results) => {
console.log(“done adding item”)
} )
. catch ( (err) => {
let errorMsg = err;
} );
}

So you are displaying the info from the Job Listings dataset on a page and you wish for that info to then be saved into a dataset called Applicants’.

Then have a look at using setFieldValue or setFieldValues to do it instead with a save afterwards.
Plus, with the getCurrentItem, that gets all the data, if you want a specific field then you need to use the field afterwards.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValues
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#save

Like this example here from Vorbly.
https://www.vorbly.com/Vorbly-Code/WIX-CODE-AUTO-FILL-FORM-WITH-USER-INPUTS

Hi givemewhisky!

Thanks for getting back to me.

Yes that is exactly what I am trying to do! I have read through the documents you sent me, but being a total novice, it is all very confusing to me. I have updated the getCurrentItem with the field key form that database:

import wixData from ‘wix-data’;
export function button6_Click(event, $w) {
let toInsert = $w(“#text1”).getCurrentItem(‘jobTitle’); //gets the current item
wixData.insert(“Applicants”, toInsert) //inserts the item
.then( (results) => {
console.log(“done adding item”)
} )
. catch ( (err) => {
let errorMsg = err;
} );
}

Is there anything else you could suggest to make this code work? Do I need to be more specific as to where I am sending the data/text, at the moment I have just put the name of the database but no specifics around the column/field it should populate within it…?

Also, would you recommend adding an OnReady element to the code?

It is clearly laid out on the Vorbly example page, you just need to change it to suit your own page and elements id names etc.

import wixData from 'wix-data';

// Auto-Fill Form //
$w.onReady( () => {
$w("#myJobListingsDataset").onReady( () => {
$w("#input1").value = $w("#JobListingsDataset").getCurrentItem().jobTitle;
});
​
// Submit Auto-Filled Items //
export function button6_click(event, $w) {
$w('#ApplicantsDataset').setFieldValue('jobTitle', $w('#input1').value);
$w("#myDataset").save();
)};
}

You will need to change these two in the code
#JobListingsDataset
#ApplicantsDataset
To what the actual id names of your datasets are on your page.

The same with jobTitle, check that is correct and the right field for your page to use in both your datasets.

Awesome reply, Whisky :slight_smile: