Dictionary.SetValueForKey
-------------------------

Stores value for given key.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Dictionary](component_Dictionary.md) | [5.0](newinversion50.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Dictionary.SetValueForKey"; DictionaryRef; Key; Value ) 

**MBS**( **"Dictionary.SetValueForKey";** /\* Stores value for given key. \*/  
**$DictionaryRef**; /\* The reference number to the dictionary.e.g. $dic \*/   
**$Key**; /\* The key to use. Keys are case sensitive. Also keys must be text and should be single line.e.g. "FirstName" \*/   
**$Value**) /\* The new value. Supported data types include empty, text, number, boolean, container, time, timestamp and date.e.g. "Hello World" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| DictionaryRef | The reference number to the dictionary. | $dic |
| Key | The key to use. Keys are case sensitive. Also keys must be text and should be single line. | "FirstName" |
| Value | The new value. Supported data types include empty, text, number, boolean, container, time, timestamp and date. | "Hello World" |

### Result

Returns OK or error.

### Description

Stores value for given key.  
Data type is preserved, so you can even store containers in the dictionary.  
Keys should be text and are handled case sensitive.  
### Examples

Build a dictionary in a calculation:

 Let ( \[  
/\*  
Create new Dictionary  
\*/  
 param = MBS ( "[Dictionary.Create](DictionaryCreate.md)" );  
  
/\*  
 Fill in parameters  
\*/   
 r1 = MBS ( "Dictionary.SetValueForKey"; param; "text"; Pass Parameters with Dictionary::TextField );  
 r2 = MBS ( "Dictionary.SetValueForKey"; param; "number"; Pass Parameters with Dictionary::NumberField );  
 r3 = MBS ( "Dictionary.SetValueForKey"; param; "date"; Pass Parameters with Dictionary::DateField );  
 r4 = MBS ( "Dictionary.SetValueForKey"; param; "time"; Pass Parameters with Dictionary::TimeField );  
 r5 = MBS ( "Dictionary.SetValueForKey"; param; "timestamp"; Pass Parameters with Dictionary::TimeStampField );  
 r6 = MBS ( "Dictionary.SetValueForKey"; param; "container"; Pass Parameters with Dictionary::ContainerField )  
/\*  
 return dictionary  
\*/  
 \] ; param )  
Serialize and unserialize with date and time:

 # Create Dictionary   
Set Variable \[$dict ; Value:MBS ( "[Dictionary.Create](DictionaryCreate.md)" )\]  
\# put date and time inside:   
Set Variable \[$r ; Value:MBS ( "Dictionary.SetValueForKey"; $dict ; "theTime"; Get ( CurrentTime ))\]  
Set Variable \[$r ; Value:MBS ( "Dictionary.SetValueForKey"; $dict ; "theDate"; Get ( CurrentDate ))\]  
\# Serialize this   
Set Variable \[$dictEncoded ; Value:MBS ( "[Dictionary.Serialize](DictionarySerialize.md)"; $dict )\]  
\#Free dictionary   
Set Variable \[$r ; Value:MBS ( "[Dictionary.Release](DictionaryRelease.md)"; $dict )\]  
\# Unpack it:   
Set Variable \[$newDict ; Value:MBS ( "[Dictionary.Deserialize](DictionaryDeserialize.md)"; $dictEncoded )\]  
\# and get values   
Set Variable \[$TheTime ; Value: MBS ( "[Dictionary.ValueForKey](DictionaryValueForKey.md)"; $newDict ; "theTime" )\]  
Set Variable \[$TheDate ; Value: MBS ( "[Dictionary.ValueForKey](DictionaryValueForKey.md)"; $newDict ; "theDate" )\]  
Show Custom Dialog \[$TheTime &amp; " " &amp; $TheDate \]  
Set Variable \[$r ; Value:MBS ( "[Dictionary.Release](DictionaryRelease.md)"; $newDict )\]  
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"; "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") \]  
### See also

- [Dictionary.Create](DictionaryCreate.md)
- [Dictionary.CreateNamed](DictionaryCreateNamed.md)
- [Dictionary.Deserialize](DictionaryDeserialize.md)
- [Dictionary.KeysWithPrefix](DictionaryKeysWithPrefix.md)
- [Dictionary.ToJSON](DictionaryToJSON.md)
- [Dictionary.ToMatrix](DictionaryToMatrix.md)
- [Dictionary.ToXML](DictionaryToXML.md)
- [Dictionary.ValueForKey](DictionaryValueForKey.md)
- [Dictionary.ValueTypeForKey](DictionaryValueTypeForKey.md)
- [FM.CF](FMCF.md)

### Example Databases

- [Dictionary/Dictionary Container Test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Dictionary/Dictionary%20Container%20Test.shtml#2ScriptAnchor_)
- [Dictionary/Pass Parameters with Dictionary](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Dictionary/Pass%20Parameters%20with%20Dictionary.shtml#1Button85.0000000315.0000000111.0000000498.0000000LayoutObjectAnchor_)

### Blog Entries

- [Data structures in MBS Plugin](https://www.mbsplugins.de/archive/2023-11-27/Data_structures_in_MBS_Plugin/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)
- [Passing parameters via dictionary functions](https://www.mbsplugins.de/archive/2015-03-17/Passing_parameters_via_diction/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2025, Seite 22](https://filemaker-magazin.de/neuigkeit/4290-Appetithappen-FMM_202503)

This function checks for a license.

Created 12nd December 2014 , last changed 18th June 2021

  
[Dictionary.SetTag](DictionarySetTag.md) - [Dictionary.SetVariables](DictionarySetVariables.md)

[HTML Version](DictionarySetValueForKey.shtml)