Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

x++ List of all Methods on a table.

(0) ShareShare
ReportReport
Posted on by 65

Hi.

I need to retrive a list of all methods on a table.

I tried the following

SysDictTable dTable = new SysDictTable(tableName2Id('CustInvoiceJour'));
et dictMethodSet = dTable.methods(true, true, true);

SetEnumerator iter = dictMethodSet.getEnumerator();

while (iter.moveNext())
{
dMethod = iter.current();

info(dMethod.name());
}

 I Also tried.

Microsoft.Dynamics.AX.Metadata.MetaModel.AxTable table = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetTable("CustInvoiceJour");

Microsoft.Dynamics.AX.Metadata.Core.Collections.IKeyedObjectCollection sen =  table.Methods;

for (int i = 0; sen != null && i < sen.Count; i++)

{
Microsoft.Dynamics.AX.Metadata.MetaModel.AxMethod method = sen.getObject(i);
info (method.Name);
}

Both methods have the same Issue, they do not include extension Methods.

public static class OTDTableMethod_Extension
{

public static str otdFullName(CustInvoiceJour _custInvoiceJour)
{
return 'test';
}

}

Is there anyway to get all methods for a table or anyway to get all extension methods ?

*This post is locked for comments

  • Suggested answer
    Florian Hopfner Profile Picture
    Florian Hopfner 2,451 on at
    RE: x++ List of all Methods on a table.

    Came across this issue recently and found this thread. Unfortunately, the solution proposed by Roland Steber does not work (at least not in version 10.0.10 PU 34), because ExtensionClassSupport.GetExtensionsOnType only determines the methods on the table, but not methods in extension classes of the table. Fortunately, electronic reporting has the same issue and I was able to find some standard code in class ERAxMetadata, method getAxMethodFromTableBySysDictMethod which provided the solution. Basically, you have to use method GetNamesOfExtensionsOnTypeFromSimpleName of ExtensionClassSupport instead of GetExtensionsOnType. Here is some sample code:

    using Microsoft.Dynamics.AX.Metadata.Core.MetaModel;
    using Microsoft.Dynamics.Ax.Xpp;
    [...]
        var extensionList = ExtensionClassSupport::GetNamesOfExtensionsOnTypeFromSimpleName(tableId2Name(myTableId));
        var enumerator = extensionList.GetEnumerator();
        while (enumerator.MoveNext())
        {
            AxClass axClass = MetadataSupport::GetClass(enumerator.Current);
            DictClass dictClass = new DictClass(className2Id(axClass.Name));
    
            for (int i=0; i < dictClass.staticMethodCnt(); i++)
            {
                dictMethod = dictClass.staticMethodObject(i+1);
                info(dictMethod.name());
            }           
        }
  • Suggested answer
    rolandsteber Profile Picture
    rolandsteber 55 on at
    RE: x++ List of all Methods on a table.

    Here's a code snippet in C# that should solve your problem. You can translate it into X++ if you like, but the code is much easier to write in C#.

    using Microsoft.Dynamics.AX.Metadata.Core.MetaModel;
    using Microsoft.Dynamics.Ax.Xpp;

    [...]

    var table = MetadataSupport.GetTable("YourTableName")
    var type = yourTable.GetType(); var methods = table.Methods;

    var extensions = ExtensionClassSupport.GetExtensionsOnType(type, true);
    foreach (var extension in extensions)
    {
    var extClass = MetadataSupport.GetClass(extension.Name);
    foreach (var extClassMethod in extClass.Methods)
    {
    if (!methods.Contains(extClassMethod))
    methods.Add(extClassMethod);
    }
    }

    [...]

    You can then iterate the "methods" object (Type: KeyedObjectCollection<AxMethod>) to get the metadata of the methods.
    Note: I've used the condition with "Contains" instead of a simple "AddRange", because there is the possibility of duplicates since the introduction of the ChainOfCommand feature.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: x++ List of all Methods on a table.

    That's the only correct behaviour of reflection. Extension method don't exist in the table; they're defined in completely separate classes. That they're displayed in the same way as instance method of the table is just syntactic sugar allowing you top call such static method in other classes in a nicer way. It doesn't change the definition of the table (such as its list of methods).

    I don't know if there is any easier way, nevertheless you always can iterate classes, look at which can contain extension method (they're public static and their name ends with _Extension) and check whether they have extension methods for the type (such as a table) in question.

  • XB Profile Picture
    XB 1,869 on at
    RE: x++ List of all Methods on a table.

    Sorry I didn't see that it's for Ax7

  • XB Profile Picture
    XB 1,869 on at
    RE: x++ List of all Methods on a table.

    I have this example that show all display methods I hope it help you

    private void fillMethodList()

    {

       SysDictTable            sysDictTable = new SysDictTable(tableId);

       DictMethod              dictMethod;

       DictType                dictType;

       int                     i;

       if (sysDictTable)

       {

           for (i = 1; i <= sysDictTable.objectMethodCnt(); i++)

           {

               dictMethod = sysDictTable.objectMethodObject(i);

               if (dictMethod

               && (dictMethod.displayType() == DisplayFunctionType::Get ||

                   dictMethod.displayType() == DisplayFunctionType::Set))

               {

                   dictType = new DictType(dictMethod.returnId());

                   if (dictType

                   && (dictType.baseType() == Types::String  ||

                       dictType.baseType() == Types::Integer ||

                       dictType.baseType() == Types::Real    ||

                       dictType.baseType() == Types::Date    ||

                       dictType.baseType() == Types::Enum))

                   {

                       MethodList.add(dictMethod.name());

                       methodCon += [dictMethod.name()];

                   }

               }

           }

       }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans