Programmatically Add Custom field using newly added column

i have added ‘State_id’ column in ‘Users’ table and also created one table ‘States’ which contains state id and state names.i want dropdown of all state names (present in States table) in users module.So that while creating new user admin can select state of that user from that dropdown.when user is created corresponding state-id will go in State_id column of users table.
how to do it programmatically?


You are going about it wrongly, there is no need to manually add a ‘State_id’ column in ‘Users’ table etc. What you do is go into administration then studio and find the Users module. The go to fields and add a new field of the type dropdown, this will then let you create a list of states to add to your new dropdown field. You can then use studio to place it on the layout of the module etc…

But I want State names to be retrieved from ‘State’ table that i have created.Thats requirement

Why does it need to be retrieved from a states table and not a list of states?

because we need separate table for States.and this type of arrangement we need for further customization.

In that case you should create a custom module called states, and then create a one to many relationship from states to users. Have a record in the module for each state then simple relate the user to a state when creating a new user. Doing customisations to Suite/Sugar is not as simple as just adding tables to the database and then adding code to pull it in. At least not if you want it done correctly and in an upgrade safe manner.

Also simple modules like this can be created without doing any coding using the module builder in the Admin section.

But when we create new module , 3more tables gets created…and i need to target my table

Thanks for your help Sir…

You are right but again having important fields scattered aroind several tables is a knightmare when using ETL / Reporting tools, not to mention performance…