FM.CF
-----

Calls a custom function given the name with FileMaker values.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [FM](component_FM.md) [Dictionary](component_Dictionary.md) | [11.3](newinversion113.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "FM.CF"; DictionaryRef; Name { ; Parameters... } ) 

**MBS**( **"FM.CF";** /\* Calls a custom function given the name with FileMaker values. \*/  
**$DictionaryRef**; /\* The reference number to the dictionary.  
We prefer to use [Dictionary.CreateNamed](DictionaryCreateNamed.md) to create a special dictionary named "[CF](CF.md)" and refer it globally with that name.e.g. "CF" \*/   
**$Name**; /\* The name of the function.e.g. "test" \*/   
**$Parameters...**) /\* Optional; Value to pass as parameter. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| DictionaryRef | The reference number to the dictionary.   We prefer to use [Dictionary.CreateNamed](DictionaryCreateNamed.md) to create a special dictionary named "[CF](CF.md)" and refer it globally with that name. | "CF" |  |
| Name | The name of the function. | "test" |  |
| Parameters... | Value to pass as parameter. |  | Optional |

### Result

Returns result or error.

### Description

Calls a custom function given the name with FileMaker values.  
This allows you to store expressions for custom functions in a MBS dictionary, so you can refer to them by name.  
  
Parameters are passed to the function preserving the data type.   
Please pass as many parameters as needed.  
  
If the function needs more parameter, undefined values are used to fill up.  
If the function needs less parameters, additional ones are dropped.  
There is no limit in the number of parameters for MBS Plugin here.  
Recursion is limited by FileMaker with about 200 deep. The plugin has a hard limit of 50000 for recursion, but before that, the FileMaker engine will report running out of memory.  
  
The dictionary must contain the given Name as key and as value a valid FileMaker expression. This expression may have lines on the beginning with /// to name variables, one line per variable name.  
  
The expression to evaluate can be in local language of FileMaker Pro or english.   
For Server it must always be in english.  
  
Two special variables are always defined: FunctionName and DictionaryRef with the values filled with the parameters you passed above.  
  
If you like to have a function with variable parameters, you can use ParameterIndex and ParameterCount in your calculation. To query plugin parameter values, we have MBS("FM.[CF](CF.md).Parameter"; index) to query them.  
  
See also [CF](CF.md) function for shorter access.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat Parameters parameter as often as you need.  
### Examples

Call Concat function with two parameters:

 MBS ( "FM.[CF](CF.md)"; "[CF](CF.md)"; "Concat"; "Hello"; "World")  
Call a function and pass field value, calculation and hard coded value:

 MBS ( "FM.[CF](CF.md)"; "[CF](CF.md)"; "Test"; MyTable::MyField ; Get(AccountName); "Hello"; Round($Total + ($Total \* $taxRate ); 2) )  
Create dictionary, add a function and

 # create environment   
Set Variable \[ $[CF](CF.md) ; Value: MBS ("[Dictionary.CreateNamed](DictionaryCreateNamed.md)"; "test" ) \]   
\#   
\# Register one function. Replacing older one with same name   
Set Variable \[ $FunctionName ; Value: "Greet" \]   
Set Variable \[ $Body ; Value: "/// Name¶¶\\"Welcome \\" &amp; Name &amp; \\"!\\"" \]   
Set Variable \[ $r ; Value: MBS ( "[Dictionary.SetValueForKey](DictionarySetValueForKey.md)"; "test"; $FunctionName ; $Body ) \]   
\#   
\# now run it   
Set Variable \[ $r ; Value: MBS ("FM.[CF](CF.md)"; "test"; "Greet"; "Peter") \]   
Show Custom Dialog \[ "Result" ; $r \]   
\#   
\# cleanup   
Set Variable \[ $r ; Value: MBS ("[Dictionary.Release](DictionaryRelease.md)"; "test") \]  
Defines a recursive function Count, which calls itself:

 MBS ( "[Dictionary.SetValueForKey](DictionarySetValueForKey.md)";   
"CF"; // dictionary reference  
"Count"; // function name  
"/// Value¶" &amp;   
"If ( Value &gt; 0; \\"a\\" &amp; MBS (\\"FM.[CF](CF.md)\\"; DictionaryRef; FunctionName; Value-1); \\"x\\")" )  
### See also

- [CF](CF.md)
- [Dictionary.Create](DictionaryCreate.md)
- [Dictionary.CreateNamed](DictionaryCreateNamed.md)
- [Dictionary.Release](DictionaryRelease.md)
- [Dictionary.SetValueForKey](DictionarySetValueForKey.md)
- [FM.CF.Parameter](FMCFParameter.md)
- [JS.CF](JSCF.md)

### Release notes

- **Version 14.1**
    - Added [CF](https://www.mbsplugins.eu/CF.shtml) function as a shortcut for [FM.CF](https://www.mbsplugins.eu/FMCF.shtml) function, which assumes you store custom functions in a dictionary named CF.
- **Version 11.4**
    - Added [FM.CF.Parameter](https://www.mbsplugins.eu/FMCFParameter.shtml) function.
- **Version 11.3**
    - Added [FM.CF](https://www.mbsplugins.eu/FMCF.shtml) function to run custom functions defined in a database table and managed via [Dictionary](https://www.mbsplugins.eu/component_Dictionary.shtml) functions.
    - Added recursion limit for [FM.CF](https://www.mbsplugins.eu/FMCF.shtml) with 50000 as limit, but after about 200 deep FileMaker will report running out of memory.

### Example Databases

- [Utility functions/FileMaker Custom Functions via Dictionary](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Utility%20functions/FileMaker%20Custom%20Functions%20via%20Dictionary.shtml#12912FieldAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 14.1pr2](https://www.mbsplugins.de/archive/2024-02-14/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 11.3](https://www.mbsplugins.de/archive/2021-07-27/New_in_MBS_FileMaker_Plugin_11/monkeybreadsoftware_blog_filemaker)
- [Neues MBS FileMaker Plugin 11.3](https://www.mbsplugins.de/archive/2021-07-12/Neues_MBS_FileMaker_Plugin_113/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 11.3 - More than 6500 Functions In One Plugin](https://www.mbsplugins.de/archive/2021-07-12/MBS_FileMaker_Plugin_113_-_Mor/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.3pr7](https://www.mbsplugins.de/archive/2021-07-09/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS @ FMTraining.TV](https://www.mbsplugins.de/archive/2021-07-03/MBS_@_FMTrainingTV/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.3pr4](https://www.mbsplugins.de/archive/2021-06-22/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Custom Functions stored in a database](https://www.mbsplugins.de/archive/2021-06-15/Custom_Functions_stored_in_a_d/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.3pr3](https://www.mbsplugins.de/archive/2021-06-14/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 10th June 2021 , last changed 10th February 2024

  
[FM.Beep](FMBeep.md) - [FM.CF.Parameter](FMCFParameter.md)

[HTML Version](FMCF.shtml)