Reference > Script steps reference > Control script steps > Set Variable
 

Set Variable

Sets a local or global variable to a specified value.

See also 

Options 

Name is the name of the variable you want to create. Prefix the name with $ for a local variable or $$ for a global variable. If no prefix is added, $ is automatically added to the beginning of the name.

Value is the value the variable is set to. You can enter text or specify a calculation.

Repetition is the repetition (index) number of the variable you want to create. If no repetition is specified, the default is 1.

Compatibility 

 

Product 

Supported 

FileMaker Pro Advanced 

Yes 

FileMaker Go 

Yes 

FileMaker WebDirect 

Yes 

FileMaker Server 

Yes 

FileMaker Cloud products 

Yes 

FileMaker Data API 

Yes 

Custom Web Publishing 

Yes 

Runtime solution 

Yes 

Originated in 

FileMaker Pro 8.0

Description 

If a variable doesn't exist, this script step will create one. See Using variables.

Example 1 

Creates a related record by using a local variable to copy information into a match field.

Set Variable [$CURRENT_CUSTOMER_ID; Value: Customers::Customer ID]
Go to Layout ["Invoice Details"]
New Record/Request
Set Field [Invoices::Customer ID; $CURRENT_CUSTOMER_ID]

Example 2 

Uses a local variable to save records as Excel or PDF files in the Documents folder.

Show Custom Dialog ["Save the current record as Excel or PDF?"]
If [Get ( LastMessageChoice ) = 1]
Set Variable [$PATH; Value: Get ( DocumentsPath ) & "Invoice " & Invoice::Invoice Number & ".xlsx"]
Save Records as Excel [Restore; With dialog: Off; "$PATH"; Current record ; Create folders: Off]
Else
Set Variable [$PATH; Value: Get ( DocumentsPath ) & "Invoice " & Invoice::Invoice Number & ".pdf"]
Save Records as PDF [Restore; With dialog: Off; "$PATH";
Current record ; Create folders: Off]
End If

Example 3 

Uses global variable as a toggle to stop a script from being triggered.

Script: Go to Selected Invoice for iOS

Set Variable [$$SCRIPT_TRIGGER; Value: "Off"]
Go to Layout ["Invoice Details iPad"]

Script: Trigger Entering Invoice Details

If [$$SCRIPT_TRIGGER = "Off"]
Set Variable [$$SCRIPT_TRIGGER; Value: "On"]
Exit Script [Text Result: ]
End If
Find Matching Records [Replace; Invoices::Customer Name]
Go to Record/Request/Page [First]

Related topics 

Script steps reference (alphabetical list)

Script steps reference (category list)

About formulas

Defining repeating fields