Page 1 of 1

popup to another form in subform

Posted: Mon Jul 03, 2023 7:10 pm
by johan
I am trying to create a popup in a subform like in your demo. This works but when I create a new record, the id of the form (foreign key of subform) is not populated.
Screenshot 2023-07-03 19.03.03.png
How can I include it in the popup?

Johan

Re: popup to another form in subform

Posted: Tue Jul 04, 2023 5:41 am
by kev1n
What exactly is the "open" supposed to open?
A new, unsaved records has the id -1

Re: popup to another form in subform

Posted: Tue Jul 04, 2023 8:58 am
by johan
Kev1n
It open a new form with extra info to add to the subform. That part works.
But I need the id of the main form to be saved as the foreign key of that subform.

Johan

Re: popup to another form in subform

Posted: Wed Jul 05, 2023 1:34 am
by kev1n
What do you think about the following idea? Generate a new ID for a subform record that can be used as a foreign key, and then replace the primary key with that new ID upon saving.

1. When a new subform record is added, generate a new unique ID with with

Code: Select all

nuID().slice(1)
2. Store this new ID as a foreign key in the subform record. This field will establish the relationship between the subform record and the main form record.

3. When saving the subform record, retrieve the primary key that is generated during the save operation (in PHP AS)

4. Replace the generated primary key with the new ID that was initially generated. Update the foreign key field in the subform record with the new ID.

By following these steps, you will have a new ID for the subform record that can be used as a foreign key, and when the subform is saved, the primary key will be replaced with the new ID. This ensures that the subform record is correctly associated with the main form record.

Re: popup to another form in subform

Posted: Wed Jul 05, 2023 9:33 am
by johan
Kev1n

I guess I didn't explain it properly.
I am trying to clarify with this print screen.
nbu.jpg
Thanks for your help.
Johan

Re: popup to another form in subform

Posted: Wed Jul 05, 2023 9:52 am
by kev1n
To obtain the parent record ID from the popup, you can use the function parent.nuRecordId(). Afterwards, you can store this ID in a text object.

Re: popup to another form in subform

Posted: Sun Jul 16, 2023 5:25 am
by luis_manuel
hi. This code this works for me

a) Case of details subform, where form table are the same of popup table

In Open Button Onclick()
if (nuIsNewRecord() == '-1' || nuSubformRowId(this) == '-1') {
nuMessage(['Alert','You must save berfore continue']);
}

else {
if (nuIsSaved()) {
nuPopup('151418fe772495',nuSubformRowId(this)); //Open Subform in an specific same record_id of subform_id

}
else {
nuMessage(['Alert','You must save berfore continue']);
}
}
Captura de pantalla 2023-07-15 212112111.png
b) Case passing variable to a popup from subform In response of
johan wrote: Tue Jul 04, 2023 8:58 am Kev1n
It open a new form with extra info to add to the subform. That part works.
But I need the id of the main form to be saved as the foreign key of that subform.
if you need to pass a variable what i do is

1. on OnClick evengt on Button "Open"

nuSetProperty('subform_id',nuSubformRowId(this));
nuSetProperty('main_id',nuGetProperty('record_id'));

if (nuIsNewRecord() == '-1' || nuSubformRowId(this) == '-1') {
nuMessage(['Alert','You must save berfore continue']);
}

else {
if (nuIsSaved()) {
nuPopup('151418fe772495',nuSubformRowId(this));

}
else {
nuMessage(['Alert','You must save berfore continue']);
}
}


2. In your Popup Form create a display object named "main_id" to obtain the globalvariable
Captura de pantalla 2023-07-15 210023.png
and be sure to create a field object to be filled with the foreignkey (main_id)

3. In Custom Code of Popup Form:

if (nuFormType() == 'edit') {

if (nuIsNewRecord()) {
$('#foreign_key').val($('#main_id').val()).change(); //here obtain the main_id value and write on the foreing key value
}
}
4. Hide when "main_id" display and your you foreign_key objects and finish.

Now when open the popup automatically the foreign_key will be populated with your "main_id" and you can save

Re: popup to another form in subform

Posted: Tue Jul 18, 2023 6:18 am
by johan
Louis_manuel

This is how I force the user to save the form first before going to the popup.
In that case, my foreign key is correct.
Thanks for your help.
Johan