Page 1 of 1

Retrieve data from another table on load in an edit form

Posted: Fri Apr 22, 2022 7:36 pm
by yvesf
I have 2 tables:
- Patient table
Patient_id
Patient_FirstName <-- Text
Patient_LastName <-- Text
Patient_DOB <-- Date
- Task table
Task_id
Task_Name <-- Varchar(100)
Task_select_patient <-- Select field
Task_pat_DOB <-- Display field

I don't want to save the DOB in the Task table to avoid data duplication. It is the reason why it is a display field.

In the Task Edit form, I would like to retrieve more than the firstname and the lastname but also the DOB (Date of Birth). I perform that by inserting PHP code after Browse :
$lu = nuLookupRecord();
nuSetFormValue('tsk_pat_DOB', $lu->Patient_DOB);
I retrieve the patient DOB perfectly.
But when I reopen the task record, I don't retrieve the DOB. Behind the display field I have the request "Select Patient_DOB from Patient". It doesn't retrieve the DOB of the current patient but the first DOB in the database. I have to use the Hash Cookie but I don't know how to perform that.
Could you please help ?
Many thanks,

Yves

Re: Retrieve data from another table on load in an edit form

Posted: Fri Apr 22, 2022 10:02 pm
by kev1n
You need to select the DOB of the selected patient like

Code: Select all

SELECT Patient_DOB FROM Patient
WHERE Patient_id = '#id_of_your_lookup_here#'

Re: Retrieve data from another table on load in an edit form

Posted: Sun Apr 24, 2022 3:48 pm
by yvesf
Hello Kev1n,

I am certainly doing something wrong.
Here is the display field
all.png
request.png
and the related lookup
idlookup.png
Lookup tab.png
When I open the record, it seems that the sql request behind the display field isn't executed.The display field stays empty.
displayFieldEmpty.png

Re: Retrieve data from another table on load in an edit form

Posted: Sun Apr 24, 2022 3:56 pm
by kev1n
Try with lowercase: #id_patient#

Re: Retrieve data from another table on load in an edit form

Posted: Sun Apr 24, 2022 5:47 pm
by yvesf
Yes of course, brilliant Kev1n !!!