Hello Every One,
Is it possible to get the method return type in Ax2012 using x++ code.
I would like now the return data type of AOT objects like Table methods and form methods and so on.
Thanks,
Phani.
Hello Every One,
Is it possible to get the method return type in Ax2012 using x++ code.
I would like now the return data type of AOT objects like Table methods and form methods and so on.
Thanks,
Phani.
You can get a List with this way
Or you can loop all methods
static void Es_getReturnType(Args _args) { SysDictTable dictTable = new SysDictTable(tableNum(SalesLine)); SysDictMethod dictMethod;// = new SysDictMethod(UtilElementType::TableStaticMethod, tableNum(SalesLine), tableMethodStr(SalesLine, amountCur)); int i; for (i=1; i<=dictTable.objectMethodCnt(); i ) { dictMethod = dictTable.objectMethodObject(i); info(dictMethod.name() "-" extendedTypeId2DisplayName(dictMethod.returnType(),dictMethod.returnId())); } }
How you can decide it depends on what you're doing. You asked about a single implementation detail, but you gave us no context. Please do it now.
For example, maybe you want to iterate all methods of a table for some reason. Or you want to read a configurable list of methods. Or something else...
Hi Ergün Şahin,
Thanks for your reply.
I would like to write some generic code for this.
SysDictMethod dictMethod = new SysDictMethod(UtilElementType::TableInstanceMethod, tableNum(SalesLine), tableMethodStr(SalesLine, moduleType));//orderAccount));
In the above code table and method name will come dynamically. I don't know either that is instance or static method. How do I decide.
Help to complete this as well.
Thanks,
Phani
info(extendedTypeId2DisplayName(dictMethod.returnType(),dictMethod.returnId()));
It came to my mind when Martin said returnId. It is possible to get a Name by combining id and type. I have written for two cases below, others can be added.
static void Es_getReturnType(Args _args) { SysDictMethod dictMethod = new SysDictMethod(UtilElementType::TableInstanceMethod, tableNum(SalesLine), tableMethodStr(SalesLine, moduleType));//orderAccount)); switch (dictMethod.returnType()) { case Types::UserType : info(extendedTypeId2pname(dictMethod.returnId())); break; case Types::Enum : info(enumId2pname(dictMethod.returnId())); break; } //info(strFmt("%1 - %2",dictMethod.returnType(),dictMethod.returnId())); }
Sorry, I don't have any AX 2012 environment anymore. Use my code as an example of how to create a SysDictMethod instance and then use its methods suitable for your purposes (that are available in AX 2012).
I'm quite sure that AX 2012 contains returnId(), which you can use to find details about the data type (if you need them at all).
Hi Martin,
Thanks for your reply .
There is no method available like returnTypeName() in Ax2012.
Kindly recheck or suggest if any thing is missing from my end.
Thanks,
Phani
Yes, it's possible via reflection. For example:
SysDictMethod dictMethod = new SysDictMethod(UtilElementType::TableInstanceMethod, tableNum(SalesLine), tableMethodStr(SalesLine, orderAccount)); info(dictMethod.returnTypeName());
You can get basic data types
static void ES_getReturnType(Args _args) { str nameOfClass = "ClassName"; str nameOfMethod = "MethodName"; int classId; SysDictMethod sdm; Types types; ; classId = Global::className2Id(nameOfClass); sdm = new SysDictMethod(UtilElementType::ClassInstanceMethod, classId, nameOfMethod); types = sdm.returnType(); info(enum2str(Types)); }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156