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
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());
}
}
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.
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.
Sorry I didn't see that it's for Ax7
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()];
}
}
}
}
}
André Arnaud de Cal...
291,996
Super User 2025 Season 1
Martin Dráb
230,853
Most Valuable Professional
nmaenpaa
101,156