Create subrecord automaticaly
A

Hello!
I got "Appointments" table and its subtable "Treatments".
Most records in "Appointments" have one or more subrecords in "Treatments".
But for records that dont have any subrecord i want to create one record in "Treatments".

Can it be done automatically and How?

Thanks a lot!
Agassi

Ninox Profile

Sorry for asking, but why would you create an emty subrecord for each appiontment? It only creates a bigger database size this way. But still, it is possible on the 'Trigger on create' field of the appointment table if you want to. You can use the folowing code to create a subrecord:

let currRec := Id;
let i := (create Treatments);
i.(Appointments:= currRec)

this way, every time a new appontment is created, an emty subrecord is also.

Steven.

A

Steven, thank you for you answer!
I'll explain with pleasure. Besides, I need something little different to what you suggested .

These tables are Appointments and Treatments.
Each appointment can have one or more treatment assigned to it. But there are Appointments with no treatment at all, like Retouch or checkup.
In the beginning i by mistake created a couple of fields in Appointments table, but later understood that these fields belong better to Treatments table. Because those fields already had values in them, I copied them to new fields in Treatments table.
But there are Appointments that have values in those fields but don't have a treatment attached. So, I can't copy those values to Treatment for these records. But I want to do it to have consistency.

So I need to create records in Treatments for EXISTING Appointments that don't have any treatment record, to be able to copy the values of those fields.
I hope you can help me with that code also!

Bug thanks for your time!

Ninox Profile

You can do it like this: place a button in your Appointments table with the code as below: 

let currRec := Id;
let i := (create Treatments);
i.(Appointments:= currRec)
;

i.(Treatmentfield1 := Appointmentfield1);

i.(Treatmentfield2 := Appointmentfield2)

so if you come to an appointment record with the extra fields having values, you push the button and an treatment subrecord will be created and the (here in this example 2) fields will be copied in that subrecord. When all are converted, you can delete the button again and even the fields in your appointments table when no longer needed.Or you can hide the button depending if there is a value in that extra field.

Remember to rename those fieldnames in yours.

If there are too many records to update, you can automate this process also but now i have not the time to explain, after te weekend i can if needed.

Steven.

A

Thank you very much, Steven!

There are lot of such records, so automating it would be correct.

I'll dig in functions explanations and try to do it myself, but i doubt,  so if you find time someday,  it will be great!!

Thanks again!!

 

Ninox Profile

Here's an example. 

https://www.dropbox.com/s/zzcnjjxaongb8rb/Appointments.ninox?dl=0

Steven.

A

Thank you for sharing,  Steven!

I'm examining the code now!

Big thanks!!!

Reply