Page 1 of 1

Pass record id from 1 form to another linked form

Posted: Thu Jul 24, 2025 9:42 pm
by yvesf
Hello,

I’m working with two tables: patients and consultations. In the consultations table, I have a lookup field cs_patient_id that references patient_id from the patients table.

I’ve created two browse and edit forms—one for each table. From the patient form, I want to display the list of consultations related to the current patient. To do this, I’ve added a Run button that opens the consultations list, filtered by record_id. This retrieves all consultations linked to the current patient.

My questions:

Is this an efficient way to do it in terms of performance?

Would it be better to use a browse form with a WHERE clause directly filtering on record_id?

Additionally, I’ve created a second button on this patient's form to create a new consultation. It opens the consultation form, and I want to automatically populate the cs_patient_id lookup field with the current patient’s ID.

To achieve this:

I created a display field in the patient's form that retrieves patient_id with WHERE patient_id = '#RECORD_ID#'.

Then I use nuSetProperty to store this value in a global field (current_patient_id), so I can use it to populate cs_patient_id when the consultation form opens.

Is this the recommended approach, or is there a better way to pass the current RECORD_ID when opening a child form?

I’m asking because it seems RECORD_ID is not always reliably set, especially when reopening an existing patient record.
The related database :
2025-07-24_184610_68828d82f2d56_nuBuilder_backup.zip
Thanks a lot for your guidance,
Yves

Re: Pass record id from 1 form to another linked form

Posted: Fri Jul 25, 2025 7:57 am
by kev1n
Hi Yves,

To evaluate performance, load 100,000 consultation records for a single patient—e. for patient ID 688140051f83c13—and you’ll see that nuBuilder remains highly responsive without noticeable delay.

I used nuBuilder’s new Prompt Generator tool (introduced in the 4.8 release in June 2025) to generate a prompt asking ChatGPT to create 10,000 dummy consultation rows for patient 688140051f83c13. It performed flawlessly—nuBuilder handled the insert operation smoothly and stayed very fast throughout
Generate code snippets and explanations following nuBuilder conventions. Use the information below when relevant to the prompt. This context is provided to help understand requirements for generating code snippets and answering questions.
## User Input/Question:

Write PHP code to insert 10,000 dummy records into the following table:
Use nuID() to generate the primary key for the Consultations_id field.
Set cs_patient_id to a constant value: '688140051f83c13'.
Generate a random date for the cs_date field.
Set cs_pathologie to a fixed value: 1.

## Table Schemas
- **patients**: `patient_id`: varchar(25) (PK), `pat_nom`: varchar(30), `pat_prenom`: varchar(30), `pat_date_naissance`: date, `pat_sexe`: varchar(1), `pat_adresse`: text, `pat_email`: varchar(50), `pat_tel`: varchar(15), `pat_mob`: varchar(15), `pat_notes`: text, `pat_nom_jfille`: varchar(30), `pat_ss`: varchar(15), `pat_tiers_payant`: varchar(1), `pat_ald`: varchar(20), `patients_nulog`: varchar(1000), `pat_id_dsply`: varchar(100)[/code]

I pasted the AI output into a nuBuilder procedure and run it:

Code: Select all

// Example: run from a nuBuilder Procedure or PHP code section

$insertSql = "
  INSERT INTO Consultations
    (Consultations_id, cs_patient_id, cs_date, cs_pathologie)
  VALUES
    (?, ?, ?, ?)
";

$stmt = null;

// use a prepared statement once
for ($i = 0; $i < 10000; $i++) {

    // generate a new primary key
    $newId = nuID();

    // fixed patient ID
    $patientId = '688140051f83c13';

    // random date (e.g. in the past 2 years)
    $timestamp = mt_rand(strtotime('-2 years'), time());
    $date = date('Y-m-d', $timestamp);

    // pathologie always 1
    $pathologie = 1;

    // execute via nuRunQuery
    $result = nuRunQuery($insertSql, [$newId, $patientId, $date, $pathologie]);

    if ($result === -1) {
        $err = nuGetLastError();
        nuDebug("Insert failed on row $i: " . print_r($err, true));
    }
}

nuDebug("Inserted 10000 dummy Consultations records.");

Regarding your other question: you can retrieve the record ID using nuRecordId()—there's no need to use a display field.
If you open "Nouvelle consultation" in a popup window instead, you can populate the Patient directly with this code, without needing to use nuSetPropeety()/nuGetProperty():

Code: Select all

if (nuIsPopup() && nuIsNewRecord()) {
   nuSetValue('cs_patient_id', parent.nuRecordId());
}

Re: Pass record id from 1 form to another linked form

Posted: Fri Jul 25, 2025 11:19 pm
by yvesf
Great thx for this complete and incredible answer .


Yves

Re: Pass record id from 1 form to another linked form

Posted: Sat Jul 26, 2025 5:40 pm
by yvesf
Kev1n, all,

parent.nuRecordId() works only in a structure parent child (form -< frame in form / form -> popup form) and doesn't work in case of 2 linked build and edit forms. In that case you have to use nuGetProperty/nuSetProperty.
Could you please confirm this assumption ?
Many thx,

Yves

Re: Pass record id from 1 form to another linked form

Posted: Sat Jul 26, 2025 5:42 pm
by kev1n
Yes, true.