Data Dictionaries

I am not able to initialize a data dictionary. I am sure I am doing something obviously wrong.

fileglobal vMyDictionary, vMyDataToStartWith
vMyDataToStartWith = |“RecordID”,“765”,“Version”,“1”,“DateEdited”,"-674136226",“ModifiedBy”,"",“RecordType”,“Prospect - OC”,“Status”,"",“OrgCode”,“692”|

vMyDictionary = initializedictionary(vMyDataToStartWith)

I have tried local variables, initializedictionary DICTIONARY, KEY, VALUE, I have also tried vProgram=|vPeopleDictionary=initializedictionary(|+ vMyDataToStartWith+|)| what am I doing wrong?

If you really don’t need the intermediate variable vMyDataToStartWith you can go direct with:

fileglobal vMyDictionary
initializedictionary vMyDictionary, “RecordID”, “765”,“Version”, “1”,“DateEdited”, "-674136226",
    “ModifiedBy”, "", “RecordType”, “Prospect - OC”,“Status”, "", “OrgCode”, “692”

If you need the vMyDataToStartWith variable to set the actual dictionary I think you will need to use an execute statement to build and exicute it:

fileglobal vMyDictionary, vMyDataToStartWith
vMyDataToStartWith = |“RecordID”,“765”,“Version”,“1”,“DateEdited”,
     "-674136226",“ModifiedBy”,"",“RecordType”,“Prospect - OC”,“Status”,"",“OrgCode”,“692”|
execute {vMyDictionary = initializedictionary(}+vMyDataToStartWith+{)}

Hi Gary,

Thank you for the reply. I am grabbing a record from a database so I need the variable. I have tried the execute approach and it did not work

That is strange since I used this exact code below as a test and the message returned was “765” as expected.

fileglobal vMyDictionary, vMyDataToStartWith
vMyDataToStartWith = |“RecordID”,“765”,“Version”,“1”,“DateEdited”,"-674136226",“ModifiedBy”,"",“RecordType”,“Prospect - OC”,“Status”,"",“OrgCode”,“692”|
execute {vMyDictionary = initializedictionary(}+vMyDataToStartWith+{)}
message getdictionaryvalue(vMyDictionary, “RecordID”, "Nothing")

I will give it another try. I might be missing something simple as it appears in your example. Thank you Gary, much appreciated

Gary’s answer was useful, but didn’t really address the question of what you are doing wrong. You are passing a single string to the initializedictionary( function, when what is really needed is separate parameters. The fact that you have quotes and commas in the string is immaterial, it is still just a single string. So synctactically, your code is no different from

vMyDictionary = initializedictionary("hello world")

You could use:

vMyDictionary = initializedictionary("RecordID","765","Version","1", ...)

But you can’t put quotes around the whole thing.

I think the dictionaryfromarray( function might be useful to you. Then you just need to generate an array with the field names and data, but apparently you are somehow doing something almost like that already.

It might be nice in the future to have a function that automatically created a dictionary from a database record in a single step, I’ll keep that idea in mind. Since this probably won’t happen anytime soon, I’ve recorded the idea in the issue tracker.

You used dictionarytoarray( and interchanged it with dictionaryfromarray(. Are they synonyms, or was the first just a mistyping?

Dictionarytoarray( should be different, probably the same as dumpdictionary(.

Just a mistyping, thanks for the catch. There is no dictionarytoarray( function.

I’ll edit my original post to correct the typo, so if you’re reading this in the future, you can ignore these two posts :slight_smile: