I have a "browse and edit" form with a subform and, on each row of the subform, I have a button that lets me edit one row of the subform but on a new screen (with the fields laid out vertically with much more space than in the subform).
When you click on a row in the browse screen of the form, the custom code for the form runs the following code, so that we can remember the PK of the record we are editing in the edit form:-
Code: Select all
rememberRecord();
(nuFormType() == 'edit') && console.log("ID of system being edited is stored in global hash cookie 'saveithere': "+nuGetProperty('saveithere'));
function rememberRecord() {
if(nuFormType() == 'edit') {
nuSetProperty('saveithere', nuGetProperty('record_id'), true);
}
}
This part works fine and I get the expected output in the console showing that the global hash cookie has been stored (BTW, the database is pre-populated, so the ID starting with "sys" is normal here - the ID was not generated by nuBuilder):-
ID of system being edited is stored in global hash cookie 'saveithere': sys131b507ac949150
Now, in the subform, I want to create a new subform row (but in the form with more space, rather than in the subform itself), by clicking the button on the very last row of the subform (which is usually blank in the subform with the "delete" checkbox ticked). The button's onclick code is:-
Code: Select all
nuForm('<form_id_hex>', nuSubformRowId(this), '', '', '0');
console.log("Button clicked to edit record in subform with id: " + nuSubformRowId(this) + " for main form with ID: >"+nuGetProperty('record_id')+"<");
if(nuSubformRowId(this) == -1) {
console.log("nuSubformRowId(this) for this row is -1 (means: new record) and global hash cookie saveithere is: "+nuGetProperty('saveithere'));
}
Button clicked to edit record in subform with id: -1 for system with ID: ><
nuSubformRowId(this) for this row is -1 (means: new record) and global hash cookie saveithere is: undefined
The form with ID <form_id_hex> opens in the UI and its Custom Code is:-
Code: Select all
retrieveRememberedHashcookie();
function retrieveRememberedHashcookie() {
if(nuGetProperty('record_id') == -1) { // New record_id
let sysID = nuGetProperty('saveithere');
nuSetValue('fk_main_form_id', sysID);
console.log("New record, so setting fk_main_form_id (from global hash cookie saveithere) to: "+sysID);
}
}
New record, so setting fk_main_form_id (from global hash cookie saveithere) to: undefined
What's weird is:
1. I used to have this working in a previous version of nuBuilder.
2. If I CTRL-SHIFT-R at this point (=Refresh the form with ID <form_id_hex>), then it "suddenly remembers" the value of the global hash cookie and it works fine! This must be running the exact same code, I assume, yet the outcome is different when it tries again.
That is, when I do 2, I get:-
New record, so setting fk_main_form_id (from global hash cookie saveithere) to: sys131b507ac949150
The version I am seeing this issue in is:-
nuBuilder Forte 4.5
DB Version: V.4.5-2023.01.22.00
Files Version: V.4.5-2023.01.22.00
Any ideas about what is going on or how to debug this, would be appreciated!