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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 04.05.2016, 06:17   #1  
Blog bot is offline
Blog bot
Участник
 
25,607 / 848 (80) +++++++
Регистрация: 28.10.2006
dynamicsaxhints: How to make enum a mandatory field on a table
Источник: http://dynamicsaxhints.blogspot.com/...d-on-enum.html
==============

It seems obvious, just set Mandatory property on a field to Yes. Is it enough? No.

Problem description
Null value concept is important for a mandatory field, but null values are not supported in Dynamics AX. Instead there are default values for each data type and they are considered null.
For enum it is an element with value set to 0. An assumption can be made that it shouldn't be possible to select and save enum element with value 0 on mandatory field. MSDN post proves the assumption:
"when the validateField method checks whether a user has entered a value in a mandatory field ...
the first entry is not accepted in an enum type field".
In another MSDN post there is an alternative requirement:
"If you want to make an enum a mandatory field on a table, make the first outcome with the value zero, as none, with the label Not selected"
What is correct? Let's analyse. You can also jump to the conclusion section.
Solution
Let's make different enums mandatory fields on a test table.
Case 1. Enum without None element
The first element of ABCModel enum is Revenue with value 0:
Let's add a field based on the enum and set Mandatory property to Yes:
There is no indication of mandatory field and the first element with value 0 is available in lookup:
It is possible to select and save element with value 0, in SQL 0 is saved:
It is not an expected behaviour.

Case 2. Enum with None element
The first element of ABC enum is None:
Let's add a field based on the enum and set Mandatory to Yes:
The field is marked as mandatory and the element with value 0 is eliminated in lookup:
An error is thrown on attempt to save empty value:
Let's select B and save the record:
2 is saved in SQL:

Conclusion
If you want to make an enum a mandatory field on a table, then you should at least make the first element of the enum with the value 0 as None and set Mandatory property on the field to Yes. Best practises include setting Label to Not selected.

Источник: http://dynamicsaxhints.blogspot.com/...d-on-enum.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
newdynamicsax: How do I access an extended table field from C#? Blog bot DAX Blogs 0 29.04.2016 02:18
dynamicsaxhints: When is it best to use Table::find().Field or select Field from Table? Blog bot DAX Blogs 0 22.03.2016 09:11
How to make a temporary instance of a database table to be shown on the form Blog bot DAX Blogs 0 02.03.2012 01:18
dynamicsaxtraining: How to access field in a table using this field id Blog bot DAX Blogs 0 09.12.2010 02:13
CRM DE LA CREME! Some more useful javascripts for MS CRM Blog bot Dynamics CRM: Blogs 0 04.05.2010 11:05

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

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

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