jeudi 29 décembre 2011

Why, When and How to use pack and unpack methods

An object has a particular state. You want to work with the same object at a later time or another place (such as on another tier). 
Make it possible to save the state of the object in a form that can be persistently saved or transported to another tier. Moreover, make it possible to reinstantiate the object.  

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)

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. 

refer to this link to find an example.
https://community.dynamics.com/product/ax/f/33/p/67248/122709.aspx

and here is a link from MSDN tutorials
 http://msdn.microsoft.com/en-us/library/aa879675.aspx

Aucun commentaire:

Enregistrer un commentaire