Page 1 of 1
Retriever the customer_id value after having save
Posted: Fri Jan 31, 2025 1:29 pm
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
Re: Retriever the customer_id value after having save
Posted: Fri Jan 31, 2025 2:09 pm
by kev1n
customer_id is the primary key of the record?
Re: Retrieve the customer_id value after having save
Posted: Fri Jan 31, 2025 11:59 pm
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
Re: Retriever the customer_id value after having save
Posted: Sat Feb 01, 2025 7:56 am
by kev1n
The approach looks correct. Does it work?
Re: Retriever the customer_id value after having save
Posted: Sat Feb 01, 2025 8:07 pm
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
Re: Retriever the customer_id value after having save
Posted: Sun Feb 02, 2025 11:13 am
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.
Re: Retriever the customer_id value after having save
Posted: Sun Feb 02, 2025 2:35 pm
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 !!!
Re: Retriever the customer_id value after having save
Posted: Sun Feb 02, 2025 3:56 pm
by kev1n