Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Is it possible to get the method return type in Ax2012?

(0) ShareShare
ReportReport
Posted on by

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.

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Is it possible to get the method return type in Ax2012?

    You can get a List with this way

    pastedimage1621925363678v1.png

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

  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: Is it possible to get the method return type in Ax2012?

    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...

  • Community Member Profile Picture
    on at
    RE: Is it possible to get the method return type in Ax2012?

    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

  • Verified answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Is it possible to get the method return type in Ax2012?

    info(extendedTypeId2DisplayName(dictMethod.returnType(),dictMethod.returnId()));

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Is it possible to get the method return type in Ax2012?

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

  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: Is it possible to get the method return type in Ax2012?

    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).

  • Community Member Profile Picture
    on at
    RE: Is it possible to get the method return type in Ax2012?

    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

  • Suggested answer
    Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: Is it possible to get the method return type in Ax2012?

    Yes, it's possible via reflection. For example:

    SysDictMethod dictMethod = new SysDictMethod(UtilElementType::TableInstanceMethod, tableNum(SalesLine), tableMethodStr(SalesLine, orderAccount));
    info(dictMethod.returnTypeName());

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Is it possible to get the method return type in Ax2012?

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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,110 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans