save bound value from dropdown

Questions related to using nuBuilder Forte.

save bound value from dropdown

Postby Ewald » Wed Jan 22, 2020 5:19 am

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?
Ewald
 
Posts: 11
Joined: Sun Dec 22, 2019 5:04 am

Re: save bound value from dropdown

Postby admin » Wed Jan 22, 2020 8:59 am

Ewald,

You can use a Lookup for picking the FK for table1.

But I'm not sure I understand the question.


Steven
admin
Site Admin
 
Posts: 3348
Joined: Mon Jun 15, 2009 9:53 am

Re: save bound value from dropdown

Postby kev1n » Wed Jan 22, 2020 5:12 pm

Using a select object (dropdown), you can enter an SQL:

https://wiki.nubuilder.net/nubuilderfor ... b_-_Select

Something like:

Code: Select all
SELECT PRIMARY_KEY_TABLE2, SOME_VALUE_TABLE2 FROM TABLE2


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.
kev1n
 
Posts: 969
Joined: Mon Oct 15, 2018 2:13 am

Re: save bound value from dropdown

Postby Ewald » Thu Jan 23, 2020 12:53 am

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.
Ewald
 
Posts: 11
Joined: Sun Dec 22, 2019 5:04 am

Re: save bound value from dropdown

Postby kev1n » Thu Jan 23, 2020 8:15 am

It would certainly help if you could upload some screenshots of the object settings where we see the SQL, the Id of the object.
kev1n
 
Posts: 969
Joined: Mon Oct 15, 2018 2:13 am

Re: save bound value from dropdown

Postby Ewald » Thu Jan 23, 2020 10:04 pm

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.
Attachments
DropdownProblem.png
Screenshots form and dropdown select tab
DropdownProblem.png (51.92 KiB) Viewed 1980 times
Ewald
 
Posts: 11
Joined: Sun Dec 22, 2019 5:04 am

Re: save bound value from dropdown

Postby kev1n » Thu Jan 23, 2020 11:09 pm

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")
tbTest.png
tbTest.png (26.22 KiB) Viewed 1976 times


Table 2: tbTypeAppraisal:
tbTypeAppraisal.png
tbTypeAppraisal.png (24.38 KiB) Viewed 1976 times


Then I added two rows with dummy data in table: tbTypeAppraisal
tbTypeAppraisal_data.png
tbTypeAppraisal_data.png (9.61 KiB) Viewed 1976 times


Then I created a nuBuilder form with an object IDTypeAppraisal:
All.png
All.png (11.08 KiB) Viewed 1976 times




..with this SQL:
sql.png
sql.png (13.84 KiB) Viewed 1976 times


Finally, I picked a value from the dropdown and saved the form

As you see, the data is saved in the table:
tbTest_data.png
tbTest_data.png (5.2 KiB) Viewed 1976 times
Last edited by kev1n on Fri Jan 24, 2020 12:10 pm, edited 1 time in total.
kev1n
 
Posts: 969
Joined: Mon Oct 15, 2018 2:13 am

Re: save bound value from dropdown

Postby Ewald » Thu Jan 23, 2020 11:29 pm

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.
Ewald
 
Posts: 11
Joined: Sun Dec 22, 2019 5:04 am

Re: save bound value from dropdown

Postby Ewald » Fri Jan 24, 2020 12:32 am

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.
Ewald
 
Posts: 11
Joined: Sun Dec 22, 2019 5:04 am

Re: save bound value from dropdown

Postby kev1n » Fri Jan 24, 2020 1:08 am

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.
Last edited by kev1n on Fri Jan 24, 2020 3:15 am, edited 1 time in total.
kev1n
 
Posts: 969
Joined: Mon Oct 15, 2018 2:13 am

Next

Return to General