Filling fields with data from another table

Husmann

New member
Hello,
i have a problem and would be happy about any way of solving this.
I got two tables, one has mashines in it with information about the customer that bought it.
the relevant fields in this case are:
Mashnr --- this is a unique ID for each mashine that we build/sell
Mashtype -- the type of mashine he got
company_name --- this is the name of the company that bought/rented it
order_id --- the ID the customer got for that specific order


The other one is a bugreport table where our technicans can put their reports about failures on mashines
This table also got the fields Maschnr, Mashtype, Company_name and order ID

In general (at least when we are done filling the table) every mashine that comes up in the bugreport table, has an entry in the mashine table. So the customer_name, orderID, mashnr and Mashtype is known.


Is there a way in dadabik, that when a new bug report is created and the person fills in the field "Mashnr" that all the other data from the other table is used to fill in the fields Mashtype, company_name and order_id ?

I dont mind if its a button you can press i the "create form", if it happens automaticly after typing in the mashnr in the "create form" or if it happens the moment i hit the "insert new item" button. Anything here will work fine for me.

Looking forward for an answer!
 

eugenio

Administrator
Staff member
Hello,
there are at least two way to do it:

1) Calculated fields: for Mashtype, Company_name and order ID you create a calculated field function that takes in input Mashnr and use it to retrieve the other info. In this case, the fields are automatically filled in the insert form, after the user specify Mashnr

2) After insert hook: the user only specify Mashnr during insert, then an after insert hook funciton fill the other fields with an update query (the function receive in input the id of the bug report just inserted - if the id is autoincrement - so you can get Mashnr and in turns all the other info from the table mashines)

I think, however, that you should re-think the structure of your db, why do you need in the table bug reports information that you already have in the table mashines?

Best,
 
Top