pack() and unpack()


im new in axapta nad im learning using the book of steen anderseeen.

Can someone explain to me ne exact role of pack and unpack in the the runbase framework because I did not udnerstand it clearly in the book.

Thanks for your patience

Well, basically, the pack method serializes the object, and unpack deserializes it.
What this gives you is the ability to automatically have all the variables set to specific values next time the job (class) is run.

For example, you have a class that prompts the user for an ItemId and does something with this item.
Each time the job is run, the user would have to select the item again, if it were not for the pack/unpack methods.

All you have to do to use them is declare the needed variables in the classDeclaration, add a macro defining the CurrentVersion of the parameterList and implement the pack and unpack methods. (the code is in the RunBase class - just copy it (removing #if.never, of course)

That is a good explanation from Kashperuk :slight_smile:

Please note that the information that is saved / restored is per user & per company basis.

The important thing to remember is - version id. If you change the contents of container, you should remember to increment the version id.


Thanks a real lot both of you.

Much appreciated.


Refer this link. Explained with example.

Where do i exactly write pack() and unpack() methods…in form, in reports, in querries…i have seen quite a few examples but complex ones. i want to see the basic simple example using pack and unpac k…pls help

They are typically used in classes and reports, but you can use them in forms too (reports and forms are technically classes). (I don’t see any reason why to use them in queries.)

It all depends on what you want to do and whether all references can be serialized.

A trivial implementation could look like this:

class SerializableObject
    // object state - all data you need to serialize
    int state1;
    bool state2;

    container pack()
        // state is serialized to container (= binary data)
        return [state1, state2];

    boolean unpack(container _packedClass)
        // state is deserialized from container back to instance variables
        [state, state2] = _packedClass;
        return true;


Nevertheless such an implementation is too simple - it’s difficult and error-prone to add additonal state fields. That’s why the usual pattern uses #CurrentList, #CurrentVersion and such things.

Very valuable points.