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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.10.2006, 18:22   #1  
Blog bot is offline
Blog bot
Участник
 
25,640 / 848 (80) +++++++
Регистрация: 28.10.2006
Axapta Lessons: Merge Customer Records
Источник: http://axapta-lessons-learned.blogsp...r-records.html
==============
Is it difficult to merge two Customer records in Axapta? No it is actually quite simple as I learned a while back from other people. I will explain the way it works hereafter. I will use the method merge() which belongs to the system class xRecord.

The Class xRecord contains the method merge(). The method merge(), when used, will move the children belonging to the selected record - the record the method is performed on - to the record that is passed as the parameter.

The condition is that the mergeInto record exists. After a succesfull move the mergeFrom parent is deleted. However I noticed no error is thrown when the mergeInto record does not exist and the mergeFrom parent simply vanishes, is deleted. In that case records in related tables will no longer be accessible using standard forms.
That is why I first validate whether both records exist in the CustTable before executing the merge.

The merge() method takes care of all the related tables - the children - and when duplicate records are encountered in one of these an error is thrown and the merge is aborted.

This can happen when records exist in the tables:
- SalesJournalAutoSummary
- GatewayOrgRef
- smmBusRelTable
- SalesPrintCopies

All we have to do is delete duplicate records on beforehand in the job and print the values of the records being deleted. So we can manually update the mergeInto records if necessary.

I will use the record set operation "delete_from" to delete these records. The record set operation "delete_from" is internally converted into a "while select" and subsequent "delete" calls. When we want to print the values of the records we have to write a while select statement ourselve and in the while loop print or log the values of all records being deleted.

The while loop to write could look like this:


Be carefull values of the mergeFrom parent record are not copied into the mergeInto record. This means that when the currency of both customer records are different the currency record of the mergeInto is valid after the merge.

Which can "possibly" result in incorrect amounts shown in reports or documents printed after the merge. In case of sales orders only the customer account is changed into the mergeInto value after executing the merge.

Now lets have a look at the job I created to merge customers. The customer records are stored in the table CustTable.

Start with the declaration of the job, called it "UTIL_Merge_CustTable". Next the declaration of all objects and variables used in the job is done.



Here is the part where the dialog is defined and the user asked for input of the custmer from (mergeFrom) and to (mergeInto) account number. At the same time the log file name is requested and access to the file is enabled and writing is set to Append.



But the most important part are the lines that explain the processing of the merge.


The first part is to ensure that both records mergeFrom and mergeInto exist. Otherwise if the latter would not exist the mergeFrom record is deleted.

The delete_from statements ensure that no duplicate records are created during the merge. Those duplicate records would abort the merge and roll back the transaction.

Finally the source code lines that end the processing block and the job are created.
Especially important here is the catch block that is executed when the merge command throws errors. These errors are thrown when duplicate records in the children - the related tables appear. We have of course tried to eliminate these errors.




[End of Lesson]


==============
Источник: http://axapta-lessons-learned.blogsp...r-records.html
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dax-lessons: Active directory in Axapta Blog bot DAX Blogs 0 27.08.2007 23:00
Axapta Lessons: Axapta DLLs Blog bot DAX Blogs 0 28.10.2006 18:22
Axapta Lessons: Export a table to a file Blog bot DAX Blogs 0 28.10.2006 18:22
Axapta Lessons: Integrating Microsoft Axapta with Microsoft Office and Microsoft SharePoint Blog bot DAX Blogs 0 28.10.2006 18:22
Введение в Аксапту Роман Кошелев DAX: Прочие вопросы 0 18.12.2001 14:00
Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 00:00.