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.
How can I include it in the popup?
Johan
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
popup to another form in subform
popup to another form in subform
You do not have the required permissions to view the files attached to this post.
-
- 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
What exactly is the "open" supposed to open?
A new, unsaved records has the id -1
A new, unsaved records has the id -1
Re: popup to another form in subform
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
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
-
- 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
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
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.
1. When a new subform record is added, generate a new unique ID with with
Code: Select all
nuID().slice(1)
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
Kev1n
I guess I didn't explain it properly.
I am trying to clarify with this print screen.
Thanks for your help.
Johan
I guess I didn't explain it properly.
I am trying to clarify with this print screen.
Thanks for your help.
Johan
You do not have the required permissions to view the files attached to this post.
-
- 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
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.
-
- Posts: 2
- Joined: Tue Jan 11, 2022 7:18 pm
- Has thanked: 16 times
Re: popup to another form in subform
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']);
}
} b) Case passing variable to a popup from subform In response of
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 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
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']);
}
} b) Case passing variable to a popup from subform In response of
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 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.
Re: popup to another form in subform
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
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