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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 04.11.2016, 00:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
goshoom: New metadata API
Источник: http://dev.goshoom.net/en/2016/11/new-metadata-api/
==============

AX 7 (“Microsoft Dynamics 365 for Operations”) offers a new API for getting metadata of AX elements such as tables, form extensions, models and so on. It’s very easy to use, therefore even if you’re very familiar with the old TreeNode API, you should definitely pay attention to this new one.

The best place to start is in the MetadataSupport class in Microsoft.Dynamics.Ax.Xpp namespace (yes, the whole API is in an external library; it’s not written in X++).

The class offers many static methods providing information about elements. Taking tables as an example, you can use:
  • TableNames() to get a list of names of all tables in Dynamics AX.
  • GetAllTables() to get details of all tables as objects.
  • GetTable() to get details of an individual table (based on its name or ID).
The MetadataSupport class also offers a few helper methods such as IsTableMapped() and ConvertAxUserTypeToBaseType().

Element details are represented by classes with names prefixed with Ax. For example, GetTable() returns an instance of AxTable class. (All these classes are defined in another assembly; the namespace is Microsoft.Dynamics.AX.Metadata.MetaModel).

These classes provide all details you may need. For tables, you can see properties, fields, indexes, methods and everything else.



Let me give you a full example that you can take and run in your environment. It iterates all controls in a given form and put their names to infolog.

X++:
using Microsoft.Dynamics.AX.Metadata.MetaModel;
 
class MetadataDemo
{        
    public static void main(Args _args)
    {        
        AxForm form = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetForm(formStr(SysUserSetup));
        new MetadataDemo().showControlNames(form.Design);
    }
 
    private void showControlNames(IFormControlCollection _control)
    {
        var controlEnumerator = _control.Controls.GetEnumerator();
 
        while (controlEnumerator.MoveNext())
        {
            AxFormControl control = controlEnumerator.Current;
            if (control is IFormControlCollection)
            {
                this.showControlNames(control as IFormControlCollection); // Recursion
            }
            else
            {
                info(control.Name);
            }
        }
    }
 
}

There are a few things to notice:
  • It starts with using Microsoft.Dynamics.AX.Metadata.MetaModel, so we don’t have to repeat this namespace when referring to classes such as AxFormControl.
    I didn’t bother to do the same with Microsoft.Dynamics.Ax.Xpp, because I’m referring to it just once.
  • I use IFormControlCollection interface instead of concrete classes when I need to work with something containing child controls. This also me to use the same code for the Design node as well as for container controls such as tab pages, because they all implement this interface. Such interfaces are extremely useful for writing generic code and fortunately they’re used quite a lot in this framework.
  • Notice that AX 7 allows us to use property names directly (e.g. form.Design), so we don’t have to resort to the underlying accessor methods (e.g. form.get_Design()) as in previous versions . It makes programming easier and code nicer.
  • As a side note, notice the comment pointing out the recursive call. I tend to always do that, to make the use of reflection immediately obvious.
I truly enjoy working with this new metadata API – it’s nicely designed and easy to use. The only problem might be that you need to be a bit familiar with .NET Interop (= accessing .NET objects from X++), but even if you aren’t, you’ll quickly learn those few things you need.



Источник: http://dev.goshoom.net/en/2016/11/new-metadata-api/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Последний раз редактировалось mazzy; 04.11.2016 в 08:20.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
goshoom: Code snippets in AX 7 – The Problem Blog bot DAX Blogs 0 30.06.2016 12:11
Microsoft Dynamics CRM Team Blog: Onboarding to Web API for Dynamics CRM 2016 from Web API Preview Blog bot Dynamics CRM: Blogs 0 17.02.2016 05:25
goshoom: Preview of Release Management Blog bot DAX Blogs 0 15.10.2015 12:11
Microsoft Dynamics CRM Team Blog: New Technical Article: Query Metadata Using JavaScript Blog bot Dynamics CRM: Blogs 0 26.01.2013 02:14
Microsoft Dynamics CRM Team Blog: New and Improved Metadata Browser for Microsoft Dynamics CRM 2011 Blog bot Dynamics CRM: Blogs 0 15.01.2013 09:11

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

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

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