Populate new record field from query result
Posted: Sat Mar 02, 2024 6:08 am
I know this must be easy to do, but I've gotten on the wrong track.
I have a form that has a field which, for new records, should default to the result of a query. I created a simple procedure:
with the code:
code:NextXYZId
PHP:
Then in the custom code of the xyz_id input object of the edit form I have:
onnuload :
if (nuIsNewRecord()){
console.log("It is a new record");
nuRunPHPHidden("NextXYZId");
}
Obviously this isn't right but how is it supposed to work?
I have a form that has a field which, for new records, should default to the result of a query. I created a simple procedure:
with the code:
code:NextXYZId
PHP:
Code: Select all
$s = "SELECT CONCAT('XYZ',LPAD(max(RIGHT(xyz_id,6)+1),6,'0')) as newXYZid FROM all_contacts;";
$t = nuRunQuery($s);
if (db_num_rows($t) == 1) {
$r = db_fetch_object($t);
nuSetFormValue('xyz_id', $r->newXYZid);
}
Then in the custom code of the xyz_id input object of the edit form I have:
onnuload :
if (nuIsNewRecord()){
console.log("It is a new record");
nuRunPHPHidden("NextXYZId");
}
Obviously this isn't right but how is it supposed to work?