Combining Values Of Two Datasets If "Name="

Hey guys. I’m just starting with coding here on wix. I was already a little successful but now I’m pretty much stuck. I have a pretty large dataset where I want to integrate a second one, or at least the data of it.

Check out the picture

The idea is having one big dataset with different values, information.
And on the other side just a short one with two fields.

On my dynamic page I want a text field that will be filled with the “Area” of “Dataset1” if the “name” of “Dataset1” = “name” of Dataset2". I was thinking about a reference filed, but maybe it’s better to solve with a java backend function.

I would love if someone could help me out. Thanks!!
Sam

Doesn’t the dynamic page only display one item from dataset 1?
I will do this:

$w.onReady(async function () {
    let name = $w("dataset1").getCurrentItem().name;
    const res = await searchDatasetTwo(name);
    if( res === 1){
        /// current name exists in dataset2
    }
    else{
        /// does not exist
    }
})

export function searchDatasetTwo(name)
let returnValue
return wixData.query("datasetTwo")
.eq("name", name)
.find()
.then((res) => {
    if (res.totalCount > 0){
        returnValue = 1
    }
    else {
        returnValue = 0;
    }
    return (returnValue)
})

Thanks a lot, so far it’ not yet working.

My specific data is:

when owner02 = title → then theRentalConditions01 to text765

text764 is the element I want to show the html-text of theRentalConditions01

import wixData from 'wix-data'
$w.onReady(async function () {
 let Owner = $w("dynamicDataset").getCurrentItem().Owner02;
 const res = await searchDatasetTwo(Owner);
 if( res !== 0){
 /// current name exists in dataset2
        $w("#text764").text = res
    }
 else{
        console.log("no result")
    }
})

export function searchDatasetTwo(Owner){
let returnValue
return wixData.query("RentalConditions01")
.eq("title", Owner)
.find()
.then((res) => {
 if (res.totalCount > 0){
        returnValue = res.items[0].theRentalConditions01
    }
 else {
        returnValue = 0;
    }
 return (returnValue)
})
}


You are a legend!! It worked. Thanks a lot!!!

import wixData from 'wix-data'

$w.onReady(async function () {
let Owner02 = $w(“#dynamicDataset”).getCurrentItem().owner02;
const res = await searchDatasetTwo(Owner02);
if( res !== 0){
/// current name exists in dataset2
$w(“#text764”).html = res
}
else{
console.log(“no result”)
}
})

export function searchDatasetTwo(Owner02){
let returnValue
return wixData.query(“RentalConditions01”)
.eq(“title”, Owner02)
.find()
.then((res) => {
if (res.totalCount > 0){
returnValue = res.items[0].theRentalConditions01
}
else {
returnValue = 0;
}
return (returnValue)
})
}