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.
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:
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: