Page 1 of 1

subforms and display object

Posted: Thu Mar 06, 2025 12:58 am
by yvesf
hi,

I have a form with a subform showing payments (amount and type: checks, cash, credit card).
I calculate the total in a "calc" object and totals per payment type in "display" objects.
I want these totals in the parent browse form, but "display" values aren’t stored in the database and can’t be shown there.
How can I display the overall total and totals per payment type in the browse form?
Is there an object like "display" that saves calculations to the database for use in the browse form query, or
........another solution?
thx,

Yves

Re: subforms and display object

Posted: Thu Mar 06, 2025 2:28 am
by steven
Yves,

Can you share your database with us?


Steven

Re: subforms and display object

Posted: Thu Mar 06, 2025 9:19 am
by Gnu
Maybe you can use PHP code in the “After Save” event to write the value directly to the database:

Code: Select all

// In the “After Save” tab of the form
$displayValue = nuGetValue('object_id'); // Get the value of the display object
$recordId = $GLOBALS['nu_record']['id']; // Primary key of the current data record

if ($displayValue !== null) {
    nuRunQuery("UPDATE table SET display = ? WHERE id = ?”, [$displayValue, $recordId]);
}
nuGetValue('object_id') retrieves the current value of an object from the form.
$GLOBALS['nu_record']['id'] contains the ID of the currently saved record (make sure your table has an id field).

(not tested)

Re: subforms and display object

Posted: Thu Mar 06, 2025 10:17 am
by kev1n
yvesf wrote: Thu Mar 06, 2025 12:58 am but "display" values aren’t stored in the database and can’t be shown there.
Values of Display objects are stored in the database if you add the "nuEdited" class.

E.g.

Code: Select all

$('#display_object_id').addClass('nuEdited');

Re: subforms and display object

Posted: Fri Mar 07, 2025 3:31 pm
by yvesf
I have put this code on the nuload event , custom tab of the related display object. It works !!! How can I update all the records without having to open records one by one and save it on previous records prior to this change ?

Yves

Re: subforms and display object

Posted: Tue Mar 18, 2025 6:06 am
by kev1n
Write an SQL Query that will calculate and update the totals.