Welcome to the nuBuilder Forums!

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

Retriever the customer_id value after having save Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Retriever the customer_id value after having save

Unread post by yvesf »

Hi,


I would like to retrieve the customer_id of the current record I have just saved.
Can I retrieve it in the nuAfterSave() fonction. Or do I have to use another function to retrieve this value.
It is to update the related link in the parent record.
Thx for confirming this approach .

Yves
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Retriever the customer_id value after having save

Unread post by kev1n »

customer_id is the primary key of the record?
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Retrieve the customer_id value after having save

Unread post by yvesf »

yes it's the primary key, the one that links records between 2 tables.
I have a parent form company in which I have inside ent_customer_id. I have a button on it which opens a pop-up custom form.
Behind the pop UP button I have the following code

Code: Select all

If (!(nuGetValue('ent_customer_id')){
nuPopup ('my_id_of_customer_form','-1','');
} else { nuPopup ('my_id_of_customer_form',nuGetValue('ent_customer_id'),'');}
And in the customer form behind customer code, I thought update ent_customer_id on the onAfterSave() function.

Code: Select all

parent.nuSetValue('ent_customer_id',nuGetValue('customer_id')
Is it a correct approach ? Do I have to use the hash cookie via nuSetProperty instead ?
Many thx,



Yves
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Retriever the customer_id value after having save

Unread post by kev1n »

The approach looks correct. Does it work?
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Retriever the customer_id value after having save

Unread post by yvesf »

When I add a console.log to check the value of customer_id in the onAfterSave() event, it returns null. if you look the content of the database the primary key has been successfully updated. It seems like the primary key isn't available at that point. Which event should I use to capture this information required to link records together ?


Is this the right approach, or am I missing something? It feels like there should be a standard method for this, as linking records by opening a popup of a child form from the main form seems like a common task.

What is the best practice for handling this kind of functionality ?
Maybe use of hash cookie RECORD_ID instead of motif_id ?

Thanks in advance!
Yves
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Retriever the customer_id value after having save

Unread post by kev1n »

yvesf wrote: Sat Feb 01, 2025 8:07 pm When I add a console.log to check the value of customer_id in the onAfterSave() event, it returns null.
nuRecordId() returns the primary key.
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Retriever the customer_id value after having save

Unread post by yvesf »

thx again !!! How could I know that without you ? I would be helpful to add this function to the documentation.

Yves
PS : I have created a procedure to retrieve the primary key from the database ; Useless with this nuRecordId() function !!!
Post Reply