### Example Usage of NameFromID Source: https://www.briandunning.com/cf/1022 Demonstrates how to use the NameFromID function with sample inputs for retrieving layout names. This example shows a typical call to the function to get the name of a layout based on its ID. ```FileMaker NameFromID ( 432 ; "Layout" ; "" ) ``` -------------------------------- ### WorkDaysList FileMaker Function Sample Input and Output Source: https://www.briandunning.com/cf/1509 Demonstrates a sample input and its corresponding output for the WorkDaysList FileMaker custom function. This example shows how to specify a start date, number of days, allowed days of the week, and dates to exclude. ```FileMaker WorkDaysList ( "12/30/2005" ; "3" ; "1234567" ; "12/31/2005¶01/01/2006¶" ) ``` ```FileMaker 12/30/2005¶ 1/2/2006¶ 1/3/2006¶ ``` -------------------------------- ### Example Usage of FormatList Source: https://www.briandunning.com/cf/1177 Demonstrates the sample input and output for the FormatList function, showing how list elements are padded with spaces to a fixed length and aligned. ```FileMaker FormatList( "1¶13¶145" ; "r" ; 3 ) ``` -------------------------------- ### FileMaker FractionMath Sample Input/Output Source: https://www.briandunning.com/cf/1355 Examples demonstrating how to use the FractionMath function with different operations and the expected string outputs. These illustrate the function's ability to handle mixed numbers and produce reduced fractional results. ```FileMaker FractionMath( "1/2" ; "3/4" ; "+" ) // Output: "5/4" FractionMath( "3 3/8" ; "4 4/5" ; "x" ) // Output: "16 1/5" ``` -------------------------------- ### FileMaker CustomList Example: Get Found Count Source: https://www.briandunning.com/cf/868 An example demonstrating how to use CustomList to generate a list of values from a found set. It iterates from 1 up to the total found count, retrieving data for each record. ```FileMaker Calculation CustomList ( 1 ; Get ( FoundCount ) ; "GetNthRecord ( FirstName ; [n] )" ) ``` -------------------------------- ### PrependList Sample Input and Output Source: https://www.briandunning.com/cf/1887 Demonstrates the usage of the PrependList function with sample input and its corresponding output. This shows how a list of strings is transformed by prepending a specific text. ```FileMaker Calculation PrependList ( List ( "One" ; "Two" ; "Three" ) ; "##" ; 1 ) ``` ```Plain Text ##One ##Two ##Three ``` -------------------------------- ### ApplyToList Example with Conditional Logic (FileMaker) Source: https://www.briandunning.com/cf/895 Demonstrates a practical application of ApplyToList where a conditional function is applied to each item in a list. This example filters items based on a condition (starting with '1') and formats the output. ```FileMaker applyToList( $$array ; "Case( Left( [n] ; 1)=1; [n])"; ", ") ``` -------------------------------- ### FileMaker RandomInteger Usage Examples Source: https://www.briandunning.com/cf/710 These examples demonstrate how to call the RandomInteger custom function in FileMaker with different start and stop values, including positive, negative, and mixed ranges. They illustrate the expected output for each scenario. ```FileMaker RandomInteger ( 1; 5 ) RandomInteger ( -5; -1 ) RandomInteger ( -5; 5 ) ``` -------------------------------- ### FileMaker mkForDo Sample Input Source: https://www.briandunning.com/cf/2044 Demonstrates how to use the mkForDo function to iterate and perform calculations, showing a practical example with a counter variable. ```FileMaker mkForDo ( "counter" ; 3 ; 6 ; "counter & ""^2+1 = "" & counter * counter + 1 & " ... " " ) ``` -------------------------------- ### Calculate Quarter Start Date in FileMaker Source: https://www.briandunning.com/cf/1183 This FileMaker custom function calculates the start date of the quarter based on a given date. It takes a date as input and returns the first day of the quarter containing that date. It can also be used with get(currentdate) to find the current quarter's start date. ```FileMaker //NAME: DateQuarterBegin //PURPOSE: Pass any date and get the quarter start date based on input date. //PARAMETER: theDate //INCLUDES OTHER CUSTOM FUNCTIONS: No //AUTHOR: Chiyoko Yoshida chiyofm@gmail.com //EXAMPLE INPUT: 7/15/2010 //EXPECTED OUTPUT: 7/1/2010 Let ([ $d = theDate; $m = Month($d); $y = Year($d) ]; If ( $m > 9 ; Date (10;1;$y); If ( $m > 6 ; Date (7;1;$y); If ($m > 3 ; Date (4;1;$y); Date(1;1;$y) ))) ) ``` ```FileMaker Let ( [ d = theDate; m = Month(d); y = Year(d) ]; Case( m > 9 ; Date (10;1;y); m > 6 ; Date (7;1;y); m > 3 ; Date (4;1;y); Date(1;1;y) ) ) ``` ```FileMaker Date ( 3 * Div ( Month ( date ) - 1 ; 3 ) + 1 ; 1 ; Year ( date ) ) ``` -------------------------------- ### FileMaker Bin Function: Sample Input and Output Source: https://www.briandunning.com/cf/1517 Illustrates how to use the FileMaker Bin function with sample data. The first example shows how to determine the event segment (e.g., 'Lunch') for a given minute. The second example demonstrates how to handle boundary values, where a value on the boundary is assigned to the next higher bin. ```FileMaker Pro Bin ( 150 ; List ( "Introduction" ; "First Part" ; "Coffee Break" ; "Second Part" ; "Lunch" ; "Questions" ) ; List ( 15 ; 45 ; 20 ; 60 ; 90 ; 45 ) ) ``` ```FileMaker Pro Bin ( .5 ; List ( "First Half" ; "Second Half" ) ; List ( .5 ; .5 ) ) ``` -------------------------------- ### Example Usage of SumText FileMaker Function Source: https://www.briandunning.com/cf/497 This example demonstrates how to call the SumText function in FileMaker to concatenate all data in a 'Field' with a comma delimiter, starting from the first line. The `count(Field)` is used to determine the `TotalLines` argument for the function. ```FileMaker SumText ( Field ; count(Field) ; 1 ; "" ; "," ) ``` -------------------------------- ### Example Usage of cf_JSONrecord in FileMaker Source: https://www.briandunning.com/cf/2608 Demonstrates how to call the cf_JSONrecord function with different field list inputs. The first example uses specific field names, while the second uses the FieldNames function to dynamically get fields from a layout. ```FileMaker cf_JSONrecord ( List ( "Contact::Key", "Contact::Name"); "" ) ``` ```FileMaker cf_JSONrecord ( FieldNames ( "File Name"; "Layout Name" ); "" ) ``` -------------------------------- ### AS_FolderPathListing Function Usage Example Source: https://www.briandunning.com/cf/1340 Demonstrates the usage of the AS_FolderPathListing custom function within FileMaker. It shows how to call the function with different folder paths and how the results can be populated in a field or the clipboard. ```FileMaker Perform Applescript ( AS_FolderPathListing ( ":Macintosh HD:User:Shared:tmp:" ; "MyTable::GlobalField" ; "jpg¶jpeg" ) ) Perform Applescript ( AS_FolderPathListing ( "/Macintosh HD/User/Shared/tmp/" ; "" ; "" ) ) ``` -------------------------------- ### RemoveValuesbyLength Example Usage Source: https://www.briandunning.com/cf/1696 Demonstrates how to call the RemoveValuesbyLength custom function with a sample list and length constraints. This example shows the expected format for providing the list of values, minimum length, maximum length, and the starting value for the recursive processing. ```FileMaker Pro RemoveValuesbyLength ( "House¶dog¶sky¶big¶business¶car¶yellow" ; 4 ; 7 ; 1 ) ``` -------------------------------- ### Example Usage (FileMaker) Source: https://www.briandunning.com/cf/2112 This demonstrates how to use the CreateVCardFile function in a FileMaker script. It involves setting a variable with the returned file path and then using the Open URL script step to launch the created vCard file, allowing users to add the contact to their address book. ```FileMaker Set Variable $path = CreateVCardFile ( "Jhon" ; "Doe" ; "Example Company" ; 12345678 ; "jhon@doe.com" ; "https://jhondoe.com" ; "Main Streent Home 1" ; "Left door" ; "0123" ; "Oslo" ; "Norway" ; "Main Workstreet 1" ; "Left Door" ; 0278 ; "Oslo" ; "Norway" ) Open URL ( "file:/" & $path ) ``` -------------------------------- ### Sample Usage of PerformEquationOnList (FileMaker) Source: https://www.briandunning.com/cf/2391 Examples demonstrating how to use the PerformEquationOnList function with different inputs and options. These examples showcase calculations with numbers, dates, and factorials, along with various output formatting. ```FileMaker PerformEquationOnList ( List ( 1 ; 2 ; 3 ) ; "item ^ item"; "item" ; "evalList"; "" ) ``` ```FileMaker PerformEquationOnList ( List ( "1/1/2000" ; "1/1/2099" ; "1/1/2099") ; "GetAsDate ( item ) > Get ( CurrentDate )"; "item" ; ""; "" ) ``` ```FileMaker PerformEquationOnList ( List ( -1 ; 1 ; 2) ; "Factorial ( item )" ; "item" ; 0 ; "" ) ``` -------------------------------- ### FileMaker: Using isNull with get(ScriptParameter) Source: https://www.briandunning.com/cf/1487 Example of using the isNull function in conjunction with get(ScriptParameter) to handle potentially NULL or empty script parameters. It ensures that if the parameter is empty, it returns NULL instead of an empty string, preventing variable disappearance. ```FileMaker Let( in = get(ScriptParameter); if( in = ""; Null; in) ) ``` -------------------------------- ### ApplyToRange Example: Date Generation with Index Source: https://www.briandunning.com/cf/892 This advanced example uses ApplyToRange to generate a list of dates for a year, along with their week number. It converts the start and end dates to numbers for the range and uses both '[i]' for the week index and '[n]' for the date value, formatted as 'DD/MM/YYYY'. ```FileMaker Scripting ApplyToRange ( "[i] & \":\" & GetAsDate([n])" ; GetAsNumber(Date(1;1;2008)) ; GetAsNumber(Date(12;31;2008)) ; 7 ; "; " ) ``` -------------------------------- ### ShortestString Function Syntax Example Source: https://www.briandunning.com/cf/288 Provides the correct syntax for the ShortestString function, including its parameters and expected return type. It demonstrates how to initialize the function with an empty string for the initial comparison value. ```FileMaker Pro ShortestString ( "apple¶grape¶banana" ; "" ) ``` -------------------------------- ### SumRepetition Function Example Usage (FileMaker) Source: https://www.briandunning.com/cf/887 An example demonstrating how to call the SumRepetition custom function within a FileMaker calculation. This sample input shows how to specify a related field ('R::field_nr'), get the current repetition number, and count the related records ('R::id'). ```FileMaker SumRepetition ( "R::field_nr" ; get ( calculationrepetitionnumber) ; count ( R::id ) ) ``` -------------------------------- ### DQ_Push FileMaker Usage Example Source: https://www.briandunning.com/cf/1539 Demonstrates the typical usage sequence for the DQ_Push function in FileMaker, including initializing a deque with DQ_New() and then adding elements using DQ_Push(). ```FileMaker Set Variable [ "$myStack" ; DQ_New ( "apple" ) ) ] Set Variable [ "$dummy" ; DQ_Push ( $myStack ; "banana" ) ] ``` -------------------------------- ### FileMaker Timestamp Conversion Logic (Issue Example) Source: https://www.briandunning.com/cf/2300 This code snippet demonstrates a section of a FileMaker custom function that was reported to have issues. It attempts to convert a source string to a timestamp by combining several FileMaker Get functions. The error message indicates an issue with the `Get(CurrentTimeUTCMilliseconds)` parameter, likely due to an older FileMaker version. ```FileMaker isUnix; GetAsTimestamp ( (GetAsNumber (Left(source; 10)) ) + GetAsNumber (Timestamp ("01/01/1970" ; "00:00:00")) + GetAsNumber ( Get(CurrentTimestamp) ) //Adjust for local timezone: - Floor ( Get(CurrentTimeUTCMilliseconds)/1000) ) ``` -------------------------------- ### FormatAsDate Sample Input and Output Source: https://www.briandunning.com/cf/373 Demonstrates a typical usage scenario for the FormatAsDate function, showing how a simple numeric string representing a date is transformed into a fully formatted date. ```FileMaker Pro Advanced FormatAsDate ( "1103" ) ``` ```FileMaker Pro Advanced 01/01/2003 ``` -------------------------------- ### Parameter Formatting with Let() Function Source: https://www.briandunning.com/cf/78 This example demonstrates using the Let() function within a button's optional parameter to format multiple values, separated by paragraph characters, for script parameter passing. It allows for defining variables and constructing the parameter string. ```FileMaker Let ( [ return = "¶" action = "AddRecord"; value = some_field_value; value2 = another_value ]; action & return & value & return & value2 ) ``` -------------------------------- ### Write2Dropbox Function for FileMaker Source: https://www.briandunning.com/cf/2416 Constructs a FileMaker file path to a Dropbox folder within the user's home directory on macOS or Windows. It leverages the Get(SystemPlatform) and Get(DesktopPath) functions and assumes Dropbox is installed in its default location. The function requires appending the desired folder structure and filename to its output. ```FileMaker Case ( Get (SystemPlatform) = 1 ; "filemac:" & Substitute ( Get ( DesktopPath ) ; "Desktop/" ; "Dropbox/" ) ; Get (SystemPlatform) = -2 ; "filewin:" & Substitute ( Get ( DesktopPath ) ; "Desktop/" ; "Dropbox/" ) ; ) // Written by Samuel Toombs of Goodfaith Solutions 2020-10-21 ``` -------------------------------- ### Example Usage of TimeDispRange in FileMaker Source: https://www.briandunning.com/cf/2674 Demonstrates how to call the TimeDispRange function with sample start and end times to achieve the desired compact time range display. ```FileMaker Pro TimeDispRange ( "11:30 AM" ; "1:15 PM" ) ``` -------------------------------- ### GlobalList Sample Input and Output (FileMaker) Source: https://www.briandunning.com/cf/1050 Illustrates sample inputs and expected outputs for the GlobalList function. These examples demonstrate how different parameter combinations for table and global field filtering, as well as attribute and view options, affect the generated list of global fields. ```FileMaker GlobalList( "z_"; “_ctc_¶z_s” ; "zkv_¶zki_"; "zkv_g"; “Source” ; “1” ; “List” ) GlobalList( "z_"; “_ctc_¶z_s” ; "zkv_¶zki_"; ""; “Content” ; “0” ; “Web” ) ``` -------------------------------- ### FileMaker: ListFound_Conditionnal Function Definition Source: https://www.briandunning.com/cf/1275 The primary definition of the ListFound_Conditionnal custom function in FileMaker. It recursively traverses records to build a list of values from 'Field' where 'filterField' matches 'filterItem'. The 'start' parameter controls the recursion, and 'Get(FoundCount)' is used to determine the total number of records to check. Assumes 'start' is initialized to 1. ```FileMaker /* * ------------------------------------------- * ListFound_Conditionnal ( Field; start; filterField; filterItem) * * Result: List of values of one Field of a table under condition of the * value (filter) of a second field (filterField) of the same table * * * Result: Text Result * NOTE :start should always be set to 1 * * * Frederic Bruckert ,Tours,France Jan2011 * * ------------------------------------------- * * * inspired from Eilert Sundt * * http://www.briandunning.com/cf/1058 * * Special Thanks ! */ Case ( GetNthRecord ( filterField; start ) = filterItem ; GetNthRecord ( Field; start ) & Case ( start < Get ( FoundCount ) ; "¶" & ListFound_Conditionnal ( Field ; start + 1; filterField; filterItem )); Case ( start < Get ( FoundCount ) ; ListFound_Conditionnal ( Field ; start + 1; filterField; filterItem ) )) ``` -------------------------------- ### AS_ChooseFile Sample Usage (FileMaker) Source: https://www.briandunning.com/cf/1343 Example of how to call the AS_ChooseFile function within FileMaker. This demonstrates passing parameters for the result target, prompt message, default location, and allowed file extensions. ```filemaker Perform Applescript ( AS_ChooseFile ( "TO::FieldName" ; "Choose a file please..." ; "/Macintosh HD/Users/Shared/" ; "csv¶jpeg¶jpg" ) ) ``` -------------------------------- ### Get Date Range for a Week (WeekRange) Source: https://www.briandunning.com/filemaker-custom-functions/results_author=51837 Given a week number and a year, this function returns the date range (start and end dates) for that specific week. It is useful for calendrical calculations. ```FileMaker WeekRange ( _weekOfYear ; _year ) ``` -------------------------------- ### ApplyToList Sample Input and Output Source: https://www.briandunning.com/cf/899 Demonstrates the usage of the ApplyToList function with a sample input and its corresponding output. This example shows applying a function that squares a number to a list of numbers. ```FileMaker ApplyToList( "[n]^2"; "3¶2¶7"; ¶ ) ``` ```FileMaker "9¶4¶49" ``` -------------------------------- ### ApplyToRange Function Definition and Examples - FileMaker Source: https://www.briandunning.com/cf/892 The ApplyToRange custom function definition in FileMaker. It takes a function string, start and end values, a step, and a separator to apply the function across the specified range. Examples demonstrate various use cases including mathematical operations, date formatting, and conditional logic. ```FileMaker /* CUSTOM FUNCTION: ApplyToRange ( function ; start ; end ; step ; separator ) © 2008 Debi Fuchs of Aptworks Consulting, debi@aptworks.com Speedily (and using limited recursion) apply an "inline" function across a range of up to one million numbers. EXAMPLES: ApplyToRange ( "[n]"; 1; 1000; 1; " ") // --> "1 2 3 ... 1000" ApplyToRange ( "[n]"; 3; -3; -1; ";") // --> "3;2;1;0;-1;-2;-3" ApplyToRange ( "[n]^2"; 1; 4; 1; " ") // --> "1 4 9 16" ApplyToRange ( "[i]&":"&GetAsDate([n])"; GetAsNumber(Date(1;1;2008)); GetAsNumber(Date(12;31;2008)); 7; "; " ) // --> 1:1/1/2008; 2:1/8/2008; ...; 53:12/30/2008 ApplyToRange( "case(lg([n])=int(lg([n]));1)"; 1; 1024; 1; 0) // --> "1101000100000001..." NOTE: See "Apply" to apply a function to a single value. See "ApplyToList" to apply a function to the elements of a list rather that a range of numbers. For example, if you want to add 2 to every item in a list: 1) Don't do this (slower): ApplyToRange( "GetValue(myList; [n])+2"; 1; ValueCount( myList ); 1; " ") 2) Do this (faster): ApplyToList( "[n]+2"; myList; " " ) CREDITS: Thanks to Agnès Barouh for the idea of the "[n]" style function call syntax, and to Ray Cologon for ideas about local variables within custom functions. USAGE: ApplyToRange returns the results, delimited by "separator", of repeatedly evaluating the string "function", each time assigning to placeholder "[n]" one value in the range from "start" to "end", with a step between values as specified by the "step" parameter. For convenience in creating numbered lists, use placeholder "[i]" to represent the position of the element within the range, starting with an index of 1. Also, for compatibility with "Apply" and "ApplyToRange" the placeholder "[t]" is also provided, but there is no reason it should be needed in this function, as numbers and evaluated numbers are the same thing. FYI: While their implementations are quite different, ApplyToRange is similar in functionality to the CustomList function by Agnès Barouh: Both functions apply a function to a range of numeric values. However, ApplyToRange is all about sets, whereas while CustomList is all about building a list, so they have different focus. For example, null elements are intentionally NOT filtered from the result set of ApplyToRange, as it represents the mapping of elements to individual elements, rather than to a list at large. (To cull null values from the result set of ApplyToRange, try the CullNulls CF.) Another notable difference is that ApplyToRange does recurse (unlike CustomList, which is brilliantly non-recursive), but only minimally (see below). IMPLEMENTATION: ApplyToRange creates an "index list" of the values 0 through 1000, using it to create a string of 1000 Let statements, each representing one value in the range. After evaluating the result, it recurses in binary fashion (calling itself twice not once) on subsequent 1000-element batches of the range, such that the stack depth grows only logarithmically, not linearly. For example, when called on a range of one million values, ApplyToRange will be called 1000 times, but reach a stack depth of only 10 CF stack frames. This leaves room to use other custom functions (including ApplyToRange) within the "function" argument of ApplyToRange. ApplyToRange is maximized for speed. Suggestions for further optimization are welcome! LAST MODIFIED: 13-AUG-2008 by Debi Fuchs of Aptworks Consulting */ Let( [ // Set up some sizes and limits. range_limit = 1000000; // set a practical limit...can be higher batch_size = 1000; // avoid the FM Evaluation function limit; Note that // a maximum batch size of 1000 is hardcoded elsewhere into this // function, so do not increase it. // Determine what is involved, first coercing start/end to numbers. end = GetAsNumber(end) + 0; start = GetAsNumber(start) + 0; step = GetAsNumber(step) + 0; value_count = Int( ( end - start ) / step ) + 1; end = start + step * value_count - step; has_i = Position( function; "[i]"; 0; 1 ); has_t = Position( function; "[t]"; 0; 1 ); has_n = Position( function; "[n]"; 0; 1 ); // In the top-level call to this function, if it looks like an // index is made use of in the function, modify the "function" // argument to track the index value by including it in comments. // This way we can pass it in our recursive calls without // disturbing anything. is_first_call = Left( function; 4 ) <> "/*##"; function = Case( has_i and is_first_call; "/*##" & "00000000" & "##*/" ) & fu ``` -------------------------------- ### FileMaker NetPresentValue Sample Input and Output Source: https://www.briandunning.com/cf/961 Example usage of the NetPresentValue function with sample input values. This demonstrates how to call the function and the expected output for a given list of payments and interest rate. ```FileMaker NetPresentValue ( List ( -2000; 600; 300; 500; 700; 400 ) ; 0.5 ) ```