0

Copy text for subtable and paste in textfield in main table

Hello everyone,

 

I have problem that I cannot resolve by myself. I am a physician and I am trying to develop this database to help my patients to get information. 

 

I have a main table: 'Treatment'

I have a textfield in 'Treatment' called "what_we_treat"

 

I have a subtable: "CP"

I store  description of a disease in a textfield:  "treatment" in "CP" subtable 

On a main formula view in 'Treatment' table  on a click button I want to paste current text stored in textfield  'CP'.treatment 

Thank you for your help

3 replies

null
    • Fred
    • 2 yrs ago
    • Reported - view

    Hi there -

    Is there a reason why you need to copy data from CP to Treatment?

    Since CP is a child of Treatment there is no need to copy data, you can just show the data from CP that is related to Treatment. Create a new formula field and put this:

    first(CP.treatment)
    

    I've added first here because since CP is a child it has a 1:many relationship with Treatment. So Ninox will always return an array (even if it is one record) so you have to tell Ninox what to do. If you didn't do first (or last), then it will find all records that are related the put them together with a comma in between each result.

    To answer your question, you can put this in a button on your Treatment table.

    textfield := first(CP.treatment)
    

    This will set the field called textfield to the data that is the first related record in the CP table.

    • jmdeszczynski
    • 2 yrs ago
    • Reported - view

    Hi Fred,

    Thank you for your help.

     

    Apparently there must be something I am doing wrong because nothing shows either in the formula and button action. 

    • Fred
    • 2 yrs ago
    • Reported - view

    Can you check that there is a record in CP that is related to the record in Treatment?

    In the picture, sorry for the all the extra fields, you see that I'm in Table1 and Table2 is linked because you can see a subtable that show 2 records are related. Then in Formula 2 you see that I'm getting the Name field from the first record "Glenn". And that matches the first line in my Table 2 subtable.

    This is my code for Formula 2:

    first(Table2.Name)