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

Опции темы Поиск в этой теме Опции просмотра
Старый 14.12.2012, 23:11   #1  
Blog bot is offline
Blog bot
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
ax-erp: Debug BP errors in Dynamics AX 2012
Источник: http://microsoft-dynamics-ax-erp.blo...s-ax-2012.html

With Dynamics AX 2012, some new BP errors have been introduced. Often, while fixing BP errors, I turn to the List of Best Practice Error and Warning Messages page on MSDN for help.

But what if you are getting a BP error and there is no clear description on how to fix it. In such scenarios, I always debug the BP error and try to see what is causing this BP error in the first place.

Let us do this with a simple example.

On a Dynamics AX 2012 machine, Create a table with just two fields, ItemId and Name.

Create a normal relation on the table with InventTable on ItemId == InventTable.ItemId

On running the BP check on this table, among other BP errors, you will receive this new to Dynamics AX 2012 BP error - Only foreign key constraints are allowed on this table.

Some of you may know the reason why this BP error is being thrown. For those who do not know the reason, please hold on to that doubt, I'll explain it shortly in the end. Let us get back to the original topic of the post, how to debug this BP error and find out why it is being thrown?

If you look at the compiler output window, you will find a column titled Diagnostic ID. This is new in Dynamics AX 2012. So what does this column specify? Well, the diagnostic ID is the value of the BP error macro being thrown.

In our case, the diagnostic ID for the BP error Only foreign key constraints are allowed on this table is 839.

Now, let us open the SysBPCheck macro and search for 839. This is what we will find
view source

1.#define.BPErrorTableNaturalKeyWithRecID(839) // RecID field cannot be part of the NaturalKey index.

Ok, so this means that somewhere in code, a BP error is being raised with this macro. Copy the macro name and search in the BP classes of the object type.

The BP classes start with SysBPCheck. In our case, since the error was being thrown on a table, we will search in all the classes related to tables.
As seen in the image above, we found two instances of the macro in code. Open both the instances and check for the error message. The error in the second instance matches with the error we saw in the compiler output. So our error is being thrown from this location. If you want to confirm, you can set a break point here and run the BP check again on the table, the break point will be hit.
Now if you scroll the code a little up, you will see why this condition is being hit. The code is
view source

01.//If we need to Enforce RelationRules, Check to see if this is FK relation.
02. //If it is not and FK check is not skipped, throw BP error if:
03. //1. Not a Migrated relation (OR)
04. //2. There is no Covering PKAK Index on the related Table covering the related fields in the relation
06. if(sysDictTable.enforceRelationRules())
07. {
08. if(!foreignKeyRelation && !skipFKCheck)
09. {
10. //Dont Relax the BP error if:
11. //1. if the relation is not EDT relation (OR)
12. //2. The relation has ThisFieldFixed relationLines(OR)
13. //3. The relation has all Normal Field relations (OR)
14. //4. if the related Fields is not covered by PK or AK index in the related Table
16. if(!dictRelation.EDTRelation() || nonConfirmingRelationLines || (conLen(fixedFieldList)==0) || !relatedFieldsCoveredByPKAKIndex(joinDictTable,normalFieldList,fixedFieldList))
17. {
18. sysBPCheck.addError(#BPErrorTableNaturalKeyWithRecID,i,0,"@SYS129769"); //use i as line number to avoid reporting identical BP errors, if multiple relations have the same error.
19. }
20. }
21. }

So, in our case we see that this is not a foreign key relation hence the condition is satisfied and the error is thrown. I'll not go in the detail of the code, you can debug and find out what it means.

For those of you who were wondering the reason for this BP error, it is because we should create a new Foreign key based relation instead of a normal relation.

Simply put, when you drag and drop the ItemID EDT on the table, it will ask for your confirmation to add the relation on the EDT. The dialog will be like this
Press Yes and a Foreign key based relation will be created. If you press No and want to create the relation manually, make sure you create a Foreign key based relation and not a normal relation.

Both the normal and foreign key relation looks the same and it is visually difficult to differnetiate between them. So, if you ever encounter the above mentioned BP and have a relation defined, delete and recreate a new foreign key relation.

Источник: http://microsoft-dynamics-ax-erp.blo...s-ax-2012.html
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
ax-erp: Debug::assert() method calls in SYS layer triggering Dynamics AX 2012 debugger Blog bot DAX Blogs 0 10.12.2012 21:11
ax-erp: Creation and Posting of Purchase order in MS Dynamics AX 2012 Blog bot DAX Blogs 0 06.11.2012 15:11
ax-erp: Creating SSRS-Reports in Dynamics AX 2012 – What’s no longer possible in AX-reports Blog bot DAX Blogs 0 18.07.2012 12:11
daxline: Debug BP errors in Dynamics AX 2012 Blog bot DAX Blogs 0 28.09.2011 23:11
mfp: Microsoft Dynamics AX 2012 is here! Blog bot DAX Blogs 10 04.08.2011 17:11
Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

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