Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003

    Angry Unanswered: Creating a new Record in a Different Database

    I could swear I've done this before, but for some reason its not working. I want a script to create a new record in a different database from data in a current database record. I thought You just used "set field" or insert calculated value and it automatically created a new record with that data in the target field. For whatever reason its not working.

    I am running FM Server 7 Advanced and FMP 7 Developer. I'm having trouble updating the files even though they are both open on the Developer machine.

    Ideas? Thanks!

  2. #2
    Join Date
    Aug 2005
    Minneapolis, MN
    You can create a related record with a Set Field[] as long as the relationship is defined to 'Allow creation of records in this table via this relationship'. However, this will only create one record in the related table, and only if there's no related record already.

    If you wish to create more than one record on the many side of a one-to-many via a Set Field[], you'll need to use a filtered relationship. By changing the filter on the parent side to one that results in no related records, you can then add a new record via that Set Field[].

    For example, you could use a relationship that includes the parent key, along with the 'Type' of the child record. Then by changing the Type, you can create a related record for each Type:

    Parent <=> Child =
    Parent::ParentID = Child::ParentID
    AND Parent::gType = Child::Type

    This works great if you only need one Child record for each Type.

    For the case where you want to be able to create as many related records as needed (not tied to a specific Type,) you could use a script to first set a key (global text field) on the parent side that's based on a random number. Something like:

    Set Field [ gRandomKey ; GetAsNumber(Get(CurrentTimeStamp)) & "-" & Random * 10000 ]

    On the child side, the matching key would be a regular text field and would have no meaning other than for creating records through this relationship. The relationship would be:

    Parent <=> Child =
    Parent::ParentID = Child::ParentID
    AND Parent::gRandomKey = Child::CreateKey

    Of course, it may be simpler to just navigate to a layout based on the Child table, perform a New Record script step, then populate the foreign key and any fields you wish.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts