formtools / core

The Form Tools Core.
https://formtools.org
207 stars 78 forks source link

Auto populate field with data from a different database #784

Open jgold723 opened 3 years ago

jgold723 commented 3 years ago

Is is possible to have a field in one formtools database be automatically populated by a field from a different formtools database?

I guess I'm looking for a relational database-type set up where both databases share a common field (let's say it's the name field).

So I have database 1 that has records with names, ages, addresses, etc.

Then database 2 that has the same names, but fields for another set of data, say transactions

Ideally I don't have to go into each database separately to add names.

ghost commented 3 years ago

Hey There!

Yes - you can accomplish this in a way using the Submission Pre-Parser module. https://docs.formtools.org/modules/submission_pre_parser/

Specifically, when you save/update a record in one form, you could then have a Pre-processor script run a database action to populate a field from the form entry into another database table. You can see the examples for talking to a database here. https://docs.formtools.org/modules/submission_pre_parser/database_access/

When your transactions table writes (let's say you have a Sales Item form), you could have it set to aggregate a value (i.e. the Value of the Item) and on your Sales form you then increase the Sale by that amount on a Sales Total field. Or you can say on each save to the Sales Item form that you find all Sales Items that have been committed and then update for each to the Sales form that value. Either way the programmability is there using the Pre-parser module.

Hope this helps!