This topic is locked
[SOLVED]

 Autofill a field

7/1/2012 7:11:11 PM
PHPRunner General questions
S
stec5345 author

On an Add page, I want to autofill a certain field from another table's field based on a matching related parameter in the current table. For instance, both tables share the PhysID value but the person's name is not shared between tables. I want to add the persons name to the current Add page from the table that contains the name? Any help out there?
Steve

E
electromotive 7/1/2012

During an add, we don't have any information to start with (assuming its not adding a detail record).

If it is a detail record and PhysID is a foreign key, there will be a different solution...
So you must be entering in the PhysID value on the add form. There are several ways to do this, here's two. Depending on if you are always sure the PhysID is going to be in the other table with a name, and if PhysID is unique.

  1. SERVER. In the BeforeRecordAdded event, use the PhysID that's been entered $values["PhysID"] as a search parameter to lookup the name in the other table (assuming that PhysID is unique in the other table), then assign a $values["name"] = $data["name"]. You don't need to have the name field included on the add form, but this will overwrite whatever was entered if it was, so you might want to do this conditionally if the name field is empty. If the name is not in the second table, then you can return a false, and force the user to enter a name or do something else. The drawback is you don't see the name until the add has completed, but you get heaps of options on how to handle errors and its very efficient no matter how big the second table. They'll be code examples in the Help for the sql/DAL required to do the lookup, maybe 6 lines of code.
  2. AJAX. Set the PhysID field to be a lookup in the other table, then use the AutoFill feature to grab the name. But be cautious that if there are lots of records in the second table, then don't use a dropdown box or you'll take a big performance hit. Use an Ajax popup instead. Again if the PhysID/name is not in the second table you can stop the add if you like. Here you get to see the name as you enter in the PhysID and no coding, but errorhandling is more restrictive, and if the second table is big then its working much harder and lots of network traffic, and may even break if the second table gets enornmous with thousands of records.

S
stec5345 author 7/1/2012

Thanks Rick. I will try the server solution you mentioned as it seems most relavent. I wont close the post yet until I see if it works and is solved.
Thanks again