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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 10.03.2018, 12:16   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
palleagermark: Generic function for switching line numbers on records
Источник: http://www.agermark.com/2018/03/gene...hing-line.html
==============

Tried to write a generic routine for switching line numbers on records, to help with functions that move records up or down according to a line number sequence.

Comments are welcome and I'll update the post according to the bugs you can find. However I only spent 10 minutes on this and it's provided to you for free, so please bear that in mind before you send me death threats in the comments.

public static void switchLineNumbers(
Common _currentTopRecord,
Common _currentBottomRecord,
FieldName _lineNumberFieldName)
{
#define.RetryNum(5)
Common currentTopRecordUpdate;
Common currentBottomRecordUpdate;
LineNumber topLineNumber;
LineNumber bottomLineNumber;
FieldId lineNumberFieldFieldId = fieldName2id(_currentTopRecord.TableId, _lineNumberFieldname);

try
{
ttsBegin;

// Initialize correct table id on common
currentTopRecordUpdate = new DictTable(_currentTopRecord.TableId).makeRecord();
currentBottomRecordUpdate = new DictTable(_currentBottomRecord.TableId).makeRecord();

select firstOnly forUpdate currentTopRecordUpdate
where currentTopRecordUpdate.RecId == _currentTopRecord.RecId;

// Make a temporary line value, in case there is a unique index with line number,
// making a free spot to update the currect bottom record with
topLineNumber = currentTopRecordUpdate.(lineNumberFieldFieldId);

currentTopRecordUpdate.(lineNumberFieldFieldId) = maxInt();
currentTopRecordUpdate.update();

select firstOnly forUpdate currentBottomRecordUpdate
where currentBottomRecordUpdate.RecId == _currentBottomRecord.RecId;

bottomLineNumber = currentBottomRecordUpdate.(lineNumberFieldFieldId);

currentBottomRecordUpdate.(lineNumberFieldFieldId) = topLineNumber;
currentBottomRecordUpdate.update();

currentTopRecordUpdate.(lineNumberFieldFieldId) = bottomLineNumber;
currentTopRecordUpdate.update();

ttsCommit;
}

catch (Exception::DuplicateKeyException)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::DuplicateKeyExceptionNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::DuplicateKeyException;
}
}
}
Use at your own risk.

Источник: http://www.agermark.com/2018/03/gene...hing-line.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
german_nav_developer: Catch Me If You Can – try-catch für .NET in C/AL Blog bot Dynamics CRM: Blogs 0 22.09.2014 11:00
Nav developer: Table Information including Index information (Usage, Blocks and Reads) Blog bot Dynamics CRM: Blogs 0 25.08.2009 19:34
wiki.dynamicsbook: Changes Made in Navision Attain 3.60 Blog bot Dynamics CRM: Blogs 0 02.09.2008 13:23
NAV Sustained Engineering Team Blog: Index Usage Query Blog bot Dynamics CRM: Blogs 0 26.02.2008 12:29
Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

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