web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • XB Profile Picture
    1,875 on at

    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()];

                   }

               }

           }

       }

    }

  • XB Profile Picture
    1,875 on at

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

  • Suggested answer
    Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    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.

  • Suggested answer
    rolandsteber Profile Picture
    55 on at

    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
    Florian Hopfner Profile Picture
    2,461 on at

    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());
            }           
        }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans