nonTransactionalCreation_bare_codex

From the guide Copy your first script.

← ai2fm Guides · Download nonTransactionalCreation_bare_codex.fmscript

# Script: nonTransactionalCreation — documented copy
# Source: nonTransactionalCreation_bare.fmscript
# Purpose: Clear myTable, create 1,000 sample records, and report creation time.
# Parameters: None. Change $total below to change the intended record count.
# Requires: The named layouts, table occurrences, and fields must exist;
# Truncate Table requires Full Access privileges.
# WARNING: Truncate Table deletes every record in myTable without confirmation,
# regardless of the found set. This deletion cannot be undone and does not
# delete related records through cascading-delete relationship settings.
# This script does not use a transaction or check errors. A failure may leave
# partial results; the success dialog and JSON result do not verify completion.
# Timing includes the creation loop and final commit, but excludes truncation
# and the final layout change, resize, and dialog.
# Returns: {"success":1} as JSON when execution reaches Exit Script.
# Leaves the user on the myTableWithFields layout; does not restore the original
# layout, found set, or window size. Original executable steps are preserved.

# Prepare the interface and initialize local variables.
# $total is the intended count; $counter supplies sequential IDs starting at 1.
Freeze Window
Enter Browse Mode [ Pause: Off ]
Set Variable [ $total[1] ; Value: 1000 ]
Set Variable [ $counter[1] ; Value: 1 ]

# Establish the record-creation context and remove all existing source records.
Go to Layout [ “myTable” (myTable) ]
Adjust Window [ Resize to Fit ]
Truncate Table [ With dialog: Off ; Table: “myTable” ]

# Start measuring after the table has been cleared; timestamps are milliseconds.
Set Variable [ $startTime[1] ; Value: Get ( CurrentTimeUTCMilliseconds ) ]

# Create records with a UUID, a sequential numeric ID, and a sample text value.
# Flush type Always updates cached relationships/dependencies on data changes;
# it is not a transaction or a command to commit the entire batch.
# The exit check follows creation and increment: with $total = 1000 this attempts
# 1,000 records. Setting $total to zero or a negative value still attempts one.
Loop [ Flush type: Always ]
    New Record/Request
    Set Field [ myTable::PrimaryKey ; Get ( UUID ) ]
    Set Field [ myTable::__pkMyTableID ; $counter ]
    Set Field [ myTable::myField ; "auto-generated " & $counter ]
    Set Variable [ $counter[1] ; Value: $counter + 1 ]
    Exit Loop If [ $counter > $total ]
End Loop

# Commit the current record. This is not an atomic commit of the creation batch.
# Skip data entry validation does not bypass fields configured to Always validate.
# Force Commit concerns ESS locking conflicts; it does not guarantee success.
Commit Records/Requests [ Skip data entry validation ; With dialog: Off ; Force Commit ]

# Stop measuring and convert the elapsed milliseconds to seconds.
Set Variable [ $endTime[1] ; Value: Get ( CurrentTimeUTCMilliseconds ) ]
Set Variable [ $elapsedTime[1] ; Value: ( $endTime - $startTime ) / 1000 ]

# Switch to the display layout and report the intended count and measured time.
# The displayed count comes from $total, not from a count of saved records.
Go to Layout [ “myTableWithFields” (myTableWithFields) ]
Adjust Window [ Resize to Fit ]
Show Custom Dialog [
    Title: "Success";
    Message: $total & " Records Created at " & $elapsedTime & " seconds";
    Default Button: "OK", Commit: "Yes"
]

# Return a numeric success flag unconditionally if this step is reached.
Exit Script [
    Result: JSONSetElement (
        "{}" ;
        [ "success" ; 1 ; JSONNumber ]
    )
]

# Documentation references (Claris FileMaker Pro Help):
# https://help.claris.com/en/pro-help/content/truncate-table.html
# https://help.claris.com/en/pro-help/content/loop.html
# https://help.claris.com/en/pro-help/content/commit-records-requests.html