Pages

Monday, October 20, 2008

Saving the reference to a unique record as a string

Sometimes you have have to store a unique reference to record as a string, for example if you want to include this reference in an XML file.

Merely converting the RecId to a string is not always a good idea. The best choice for identifying the record may be another unique key of the table, especially if the table doesn't have a RecId index.

On the Global class there is a method to analyze the unique keys of a table and give you the unique key as a string. This is the record2Dynakey method.

The key is encoded in the string like this:
[fieldid:strvalue][fieldid2:strvalue][fieldid3:strvalue]

Later when you want to convert the string, representing the key, to an actual record, just call the dynaKey2Record method.

You should not use this technique for long term storage of keys, since renaming primary keys or changing the datamodel might break the ability to restore the string into the right record or restoring it in the most sufficient way.

1 comment:

Palle Agermark said...

Another way of storing the entity key is to call: \Classes\SysDictTable\getKeyData(...)

This is used by AIF.