Prefill values of a linked table

Hello! I got a table called “customers” with field called conctracts that is linked to my table contracts. When I added a new customer I want to create a new contract via the + sign of the linked table inside my customers table.

In order to create a new contract I need to asign it to a customer. This field is linked back to customers.

If I want to create a new contract inside of the table customers with the + sign i want to prefill the field with the current customer under which I want to create the contract in.

I have tried it via setValue but it does not work. Enclosed my code:

(async (doo: IDoo) => { // do not change this line
// place your code here
async function getKundenobject(id){
let d = await doo.table.getData(“kunden”);
for (let i = 0; i < d.data.length; i++){
if (d.data[i].id == id){
return d.data[i];
}
}
return null;
}

function prefill_Vertraege(kunde){
    doo.model.vertrage.setValue({
        vorZuname : kunde.fields.vorZuname
    })
}

let kundeobj = await getKundenobject(doo.model.vertrage.modelId);
if (kundeobj){
    prefill_Vertraege(kundeobj);
}

}) // do not change this line

Hi,

if you open the same record a second time, is the customer already loaded via setValue?

Regards,

Hi, if I open the customer and I want to create a contract via the linked table column inside the customer table the form “contracts form” opens up but nothing there is preselected. The contracts table has a linked column to customers. In this column I can select a customer which the contract should be assigned to.

After I create a customer I want to add a contract via the linked table column inside of the customer table and want to prefill this exact field with the specific customer name (I get the specific id with: doo.model.vertrage.modelId) under which I want to create the contract.

Thank you for you help!