Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

Опции темы Поиск в этой теме Опции просмотра
Старый 04.07.2014, 08:11   #1  
Blog bot is offline
Blog bot
24,899 / 825 (77) +++++++
Регистрация: 28.10.2006
littleax: How to transfer objects between server and client using List, Set or Map in Dynamics AX

Some time we use such structure as a list of classes. And we can get into situation, when we need to transfer our list using a container (for example between client and server or we need to print Excel report for client ...).
In this post we will try to do this operation using very simple approach.

Starting conditions. We have client site class, and hard processing. We want to transfer hard processing to the server. Let's try do something interesting ...
CMSalesOrderDataContract with some variables

class CMSalesOrderDataContract
SalesId salesId;
Qty maxQty;
Qty averageQty;

we have parm methods to access these fields

public SalesId parmSalesId(SalesId _salesId = salesId)
salesId = _salesId;
return salesId;

public Qty parmMaxQty(Qty _maxQty = maxQty)
maxQty = _maxQty;
return maxQty;

public Qty parmAverageQty(Qty _averageQty = averageQty)
averageQty = _averageQty;
return averageQty;

and simple init method
public void initFromSalesTable(SalesTable _salesTable)
SalesLine salesLine;

select maxOf(SalesQty) from salesLine
where salesLine.SalesId == _salesTable.SalesId

select avg(SalesQty) from salesLine
where salesLine.SalesId == _salesTable.SalesId

and construct method
public static CMSalesOrderDataContract construct()
return new CMSalesOrderDataContract();

Than we have 2 classes:
one collects information for us, another prints information in form;

Server class collects and saves information for us.
Declare variables
class CMCollectInformation
List salesOrdersInfo;

init list
public void new()
salesOrdersInfo = new List(Types::Class);

construct class on Server side.
public server static CMCollectInformation construct()
return new CMCollectInformation();

collect information
public void collect()
SalesTable salesTable;
CMSalesOrderDataContract salesOrderDataContract;
while select salesTable
salesOrderDataContract = CMSalesOrderDataContract::construct();

return information packed in a container
public container getPackedData()
return salesOrdersInfo.pack();

And second class allows us to print information on client side
class CMPrintInformation

initialize class strong on CLIENT side
public client static CMPrintInformation construct()
return new CMPrintInformation();

public void printInfo()
CMCollectInformation collectInformation;
ListEnumerator le;
CMSalesOrderDataContract salesOrderDataContract;
List soClientInfoList;

// create and collect information n server side
collectInformation = CMCollectInformation::construct();
soClientInfoList = List::create(collectInformation.getPackedData());
le = soClientInfoList.getEnumerator();
while (le.moveNext())
salesOrderDataContract = le.current();
info(strFmt('SalesId %1, maxQty %2, averageQty %3', salesOrderDataContract.parmSalesId(), salesOrderDataContract.parmMaxQty(), salesOrderDataContract.parmAverageQty()));

Finally let's create a job to test our work
static void Job3(Args _args)
CMPrintInformation printInformation = CMPrintInformation::construct();

An error is thrown, because our DataContract class does not contain pack and unpack methods

Let's implment a few changes in our dataContract class
Class declaration should look like

class CMSalesOrderDataContract implements SysPackable
SalesId salesId;
Qty maxQty;
Qty averageQty;



and add pack method
public container pack()
return [#CurrentVersion,#CurrentList];

and add unpack method
public boolean unpack(container packedClass)
int version = runbase::getVersion(packedClass);

switch (version)
case #CurrentVersion:
[version,#CurrentList] = packedClass;
return true;
default :
return false;

return false;

Run the job again and get a new error

We need to implement create method

public static CMSalesOrderDataContract create(container _packedClass)
CMSalesOrderDataContract salesOrderDataContract = CMSalesOrderDataContract::construct();
return salesOrderDataContract;

Try to run our job once again

Excellent result!

When we want to transfer List, Set or Map containing objects of a class between server and client we have to implement pack, unpack methods and create method. Pack and unpack methods are standard. Create method must be static and should get container as an input parameter. It should create an instance of the class, unpack variables from passed container and return the instance.

Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 16 Blog bot Dynamics CRM: Blogs 0 23.01.2014 03:15
atinkerersnotebook: Walkthrough & Tutorial Summary Blog bot DAX Blogs 1 09.09.2013 09:11
DAX: Official Dynamics AX 2012 R2 Content (update) - Where is it, and how can you find out about updates? Blog bot DAX Blogs 0 03.12.2012 11:11
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Часовой пояс GMT +3, время: 14:02.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.