Tuesday, April 20, 2010

MultiSelectionHelper class

When a developer is implementing some scenario which requires support of multiple record selection on the form he faces the problem that form datasource should be iterated on the client to avoid numerous calls from server to client (form resides on client). From the other point of view, the scenario itself most likely requires numerous database operations, so it probably should be run on server. There is a solution to this problem – datasource should be iterated on the client, fetched records serialized and passed to the server, where the main job will be executed.
In AX 2009 a new class MultiSelectionHelper was introduced to simplify the described scenario. This class can be constructed on the server and the reference to form data source can be passed into it. The MultiSelectionHelper has API to iterate records on the form datasource – getFirst() and getNext(), just like datasource itself has. But the difference is that MultiSelectionHelper will do pre-fetch of the records from the datasource first time it will be accessed, so any further calls to its methods will not cause any client\server calls.

2 comments: