Welcome to the nuBuilder Forums!

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

popup to another form in subform

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

popup to another form in subform

Unread post 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
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: popup to another form in subform

Unread post by kev1n »

What exactly is the "open" supposed to open?
A new, unsaved records has the id -1
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: popup to another form in subform

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

Re: popup to another form in subform

Unread post 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.
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: popup to another form in subform

Unread post 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
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: popup to another form in subform

Unread post 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.
luis_manuel
Posts: 2
Joined: Tue Jan 11, 2022 7:18 pm
Has thanked: 16 times

Re: popup to another form in subform

Unread post 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
You do not have the required permissions to view the files attached to this post.
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: popup to another form in subform

Unread post 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
Post Reply