How do I populate a select widget with the values from Table B in SQL which, when the form is updated, writes the value into Table A?

Hi everyone,

I’m creating a form (in a modal) to view and update the user details. The input fields are populated by a query that fetches all rows from the table “Users”. I have a column named “Type_ContractID” in the table “Users” that is related to another column named “ID” in the table “Contracts” (the relationship is one to many). The type of column “Type_ContractID” is an integer since it has to be related to “ContractID” in the table “Contracts” (an integer, primary key with auto increment). I need to create a select widget that fetches all the values from the table “Contracts” (namely, “ContractID” and “Contract_Name”) and, when the form is updated, the select widget writes the value selected by the user into the related column “Type_ContractID” in the table “Users”. Also it would be great if, when the form is opened, the select widget could take the existing value from the table “Users” (“Type_ContractID”) as a reference and display the related value from the table “Contracts” (“Contract_Name”).

Does anyone know how can I achieve this in Appsmith?

Hello Emiliano, and welcome to our community!
We have this sample app that demonstrates how to conditionally populate the values of a Select widget. The options displayed in the second Select widget are set based on the selection in the first Select widget.
Please fork this sample app to check the code and let us know if this helps.