Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Populate new record field from query result Topic is solved

Questions related to using nuBuilder Forte.
Post Reply
woodhome
Posts: 18
Joined: Mon Oct 19, 2020 8:50 am
Has thanked: 1 time

Populate new record field from query result

Unread post by woodhome »

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:

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?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Populate new record field from query result

Unread post by kev1n »

Hi,

nuSetFormValue() can only be used in the "After Browse" event of a Lookup object.
I'd use the form's 'Before Edit' event and nuAddJavaScript() as shown in this Code Library article.
woodhome
Posts: 18
Joined: Mon Oct 19, 2020 8:50 am
Has thanked: 1 time

Re: Populate new record field from query result

Unread post by woodhome »

Perfect! Just the guidance I needed.
Post Reply