1 Reply Latest reply on Apr 21, 2011 1:06 PM by philmodjunk

    Question about scripts

    NickSintich

      Title

      Question about scripts

      Post

      Hi,

      Im having a problem with a budget database that I'm working on. I would like to write a script that would automatically enter a Serial ID number in the "Payment ID Number" field, If in the "Payment Method" field "Pcard" is selected.

      Thanks,

      Nick

      screenshot_of_budget.jpg

        • 1. Re: Question about scripts
          philmodjunk

          This solution requires FileMaker 10 or later.

          Use a related table to control the generation of your serial numbers. This method is safer than some other approaches in cases where you may have two or more users generating serial numbers at the same time.

          I'll call the table for your layout "Budget". I'll assume that ID is an auto entered serial number, but if so, it should not be editable. I'd make it transparent and use Behavior in the Inspector to ban entry into this field in browse mode to keep users from being able to change this value.

          Define a new table: PaymentSerialNumbers with two fields: BudgetID (Numberfield), PaymentID (auto-entered serial number).

          Link the two tables in Manage | Database | Relationships like this:

          Budget::ID = PaymentSerialNumbers::BudgetID

          Enable "allow creation of records via this relationship" for PaymentSerialNumbers

          Replace the Payment ID Number field on your layout with PaymentSerialNumbers::PaymentID.

          Now write this script:

          If [ Budget::PaymentMethod = "Pcard"]
             Set Field [PaymentSerialNumbers::BudgetID ; Budget::ID]
          End If

          Use an OnObjectExit Script trigger on the PaymentMethod field to run this script.

          How it works: If there is no related record in PaymentSerialNumbers, the Set Field step causes such a related record to be created, the new records gets a new serial number and it appears in the field after you select the value "Pcard" in the drop down. If this should be done a second time, no harm is done as the record now already exists and the BudgetID field gets assigned the value it already has.