Here's a FileMaker script that creates a new record with a given value for the recordID
field, but skips the creation if a record with the same recordID
value already exists:
# Step 1: Get the value for the recordID field
Let ( [
newRecordID = Get ( ??? ) # Replace with the field or calculation that should provide the new recordID value
];
# Step 2: Check if a record with the given recordID already exists
If (
IsEmpty (
Get ( FoundCount )
);
# Step 3: Create a new record with the given recordID
New Record/Request;
Set Field [ $$Table::recordID; newRecordID ]
)
Here's a breakdown of the script:
Get the value for the recordID
field: The first step is to get the value that should be used for the recordID
field. This can be done by getting the value from a field or a calculation.
Check if a record with the given recordID
already exists: The script uses the Get(FoundCount)
function to check if any records with the given recordID
value already exist. If the FoundCount
is empty, it means no records were found.
Create a new record with the given recordID
: If no record with the given recordID
value was found, the script creates a new record and sets the recordID
field to the provided value.
Make sure to replace the placeholder $$Table::recordID
with the actual field name for the recordID
field in your database. Also, replace the Get(...)
function call with the appropriate field or calculation that should provide the new recordID
value.
This script will ensure that a new record is created only if a record with the given recordID
value does not already exist in the database.