tags:

views:

157

answers:

1

i have CONTACT table and ZIPCODE tabel they are related.i want a script when a user type the post code if isn't in zipcode table then get stored there.if not then get stored in CONTACT table.i'm not familiar with isempty(field) how to achieve this?please somebody help me

+1  A: 

I don't fully understand why you'd be doing things like this. Is there lots of other information stored with the Zipcode (for example geographical coordinates)?

Are you happy for lots of invalid codes to be stored in the ZIPCODE table? What happens if a user types something very wrong like AUSTRALIA?

Also, how are the CONTACT and ZIPCODE tables related? By a primary/foreign key? Or just by the zipcode?

If there is nothing "magic" about a zipcode, I would probably put it straight into the CONTACT table.

CONTACT
-------
Name
Account Number
Zipcode

If you really want them in separate tables, perhaps do this:

CONTACT
-------
Name
Account Number
Zipcode

ZIPCODE
-------
Zipcode     (Unique)

You would then need a script that did the checking for you. You wouldn't need to use IsEmpty(field) in this case.

Perhaps your use case is as follows:

  • User enters contact details, including zipcode
  • You create the contact record, and, if necessary, the zipcode record

I would do it by using a script that the user clicks once they have entered a zipcode (or if you're using FileMaker 10, a Script Trigger on the Zipcode field).

The script would do something like this:

  • Set Variable $zipcode CONTACT::Zipcode
  • Go to Layout Zipcode
  • Set Error Capture ON
  • Enter Find Mind
  • Set Field Zipcode $Zipcode
  • Perform Find
  • If (Get(Found Count) = 0)
    • New Record
    • Set Zipcode $Zipcode
    • Commit Records
  • Go to Layout (Original Layout)

That, I think, would do what you asked, but there is likely a number of better solutions to solve your actual problem.

DisplacedAussie