I have a 1:1 relation between table 1 and table 2 .
Table 1 has the primary key from table 2 as foreign key.
On a form populated with table 1 Values I want a dropdown pulling a value from table 2 and I want the primary key value from table 2 (which is the bound value of the drop down) saved in the foreign key field of table 1.
How do I do that?
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.
save bound value from dropdown
Re: save bound value from dropdown
Ewald,
You can use a Lookup for picking the FK for table1.
But I'm not sure I understand the question.
Steven
You can use a Lookup for picking the FK for table1.
But I'm not sure I understand the question.
Steven
-
- nuBuilder Team
- Posts: 4307
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 448 times
- Contact:
Re: save bound value from dropdown
Using a select object (dropdown), you can enter an SQL:
https://wiki.nubuilder.cloud/ ... b_-_Select
Something like:
The first selected value (PRIMARY_KEY_TABLE2) is the dropdown's bound value, the second one (OME_VALUE_TABLE2) its display value. While the display value is displayed in the drop-down list, the bound value is stored in the database.
https://wiki.nubuilder.cloud/ ... b_-_Select
Something like:
Code: Select all
SELECT PRIMARY_KEY_TABLE2, SOME_VALUE_TABLE2 FROM TABLE2
-
- Posts: 11
- Joined: Sat Dec 21, 2019 8:34 pm
Re: save bound value from dropdown
well, that's what I read too in the handbook and in the posts about this topic. However, if I try to do it that way it doesn't work.
I have a form based on table 1 which has a foreign key for the table 2 value, based on which I create the dropdown. I use the SQL code and the display value is visible, but the foreign key is not transfered. When I select a value from the dropdown it is visible on the form but when I hit save it dissapears again and the foreign key value in the table doesn't change. Obviously I am missing something.
I have a form based on table 1 which has a foreign key for the table 2 value, based on which I create the dropdown. I use the SQL code and the display value is visible, but the foreign key is not transfered. When I select a value from the dropdown it is visible on the form but when I hit save it dissapears again and the foreign key value in the table doesn't change. Obviously I am missing something.
-
- nuBuilder Team
- Posts: 4307
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 448 times
- Contact:
Re: save bound value from dropdown
It would certainly help if you could upload some screenshots of the object settings where we see the SQL, the Id of the object.
-
- Posts: 11
- Joined: Sat Dec 21, 2019 8:34 pm
Re: save bound value from dropdown
OK, here are some details:
Table 1 has among other fields has a foreign key field IDTypeAppraisal.
Table 2 has a primary Key IDTypeAppraisal and a field TypeAppraisal.
The form (see Attachment) shows two fields and the foreign key field of table 1. The dropdown shows the TypeAppraisal from table 2.
What I want to do is to save the bound field of the dropdown in the foreign key field of table 1.
What happens is: I select a TypeAppraisal value, it is shown properly (see Fig. 1) but upon hitting save the dropdown is empty again and the value in the foreign key field in table 1 doesn't change.
Table 1 has among other fields has a foreign key field IDTypeAppraisal.
Table 2 has a primary Key IDTypeAppraisal and a field TypeAppraisal.
The form (see Attachment) shows two fields and the foreign key field of table 1. The dropdown shows the TypeAppraisal from table 2.
What I want to do is to save the bound field of the dropdown in the foreign key field of table 1.
What happens is: I select a TypeAppraisal value, it is shown properly (see Fig. 1) but upon hitting save the dropdown is empty again and the value in the foreign key field in table 1 doesn't change.
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 4307
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 448 times
- Contact:
Re: save bound value from dropdown
I tried to reproduce your issue but I was not able to. The saving works for me.
First, I created two tables:
Table 1: tbTest (this corresponds to your "Table 1") Table 2: tbTypeAppraisal: Then I added two rows with dummy data in table: tbTypeAppraisal Then I created a nuBuilder form with an object IDTypeAppraisal:
..with this SQL: Finally, I picked a value from the dropdown and saved the form
As you see, the data is saved in the table:
First, I created two tables:
Table 1: tbTest (this corresponds to your "Table 1") Table 2: tbTypeAppraisal: Then I added two rows with dummy data in table: tbTypeAppraisal Then I created a nuBuilder form with an object IDTypeAppraisal:
..with this SQL: Finally, I picked a value from the dropdown and saved the form
As you see, the data is saved in the table:
You do not have the required permissions to view the files attached to this post.
Last edited by kev1n on Fri Jan 24, 2020 3:40 am, edited 1 time in total.
-
- Posts: 11
- Joined: Sat Dec 21, 2019 8:34 pm
Re: save bound value from dropdown
well, it looks to like I did exactly what you did. I'll start from scratch following your outline and keep you posted.
Thanks for the effort.
Thanks for the effort.
-
- Posts: 11
- Joined: Sat Dec 21, 2019 8:34 pm
Re: save bound value from dropdown
It works now, the problem was that I had the foreign key field that I wanted to change according to the selection from the dropdown on the same form. When I removed that field everything worked as expected.
In conclusion, you can't have the the field which is supposed to be populated or changed on the same form as the dropdown.
In conclusion, you can't have the the field which is supposed to be populated or changed on the same form as the dropdown.
-
- nuBuilder Team
- Posts: 4307
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 448 times
- Contact:
Re: save bound value from dropdown
Great! I am glad you figured it out!
Do you mean there where 2 objects on your form with the same Object Id? Yes, this leads to problems when saving.
Do you mean there where 2 objects on your form with the same Object Id? Yes, this leads to problems when saving.
Last edited by kev1n on Thu Jan 23, 2020 6:45 pm, edited 1 time in total.