Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

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

Posted on by Microsoft Employee

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
    ergun sahin 8,812 Super User 2024 Season 1 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
    Martin Dráb 230,188 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
    Community Member Microsoft Employee 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
    ergun sahin 8,812 Super User 2024 Season 1 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
    ergun sahin 8,812 Super User 2024 Season 1 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
    Martin Dráb 230,188 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
    Community Member Microsoft Employee 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
    Martin Dráb 230,188 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
    ergun sahin 8,812 Super User 2024 Season 1 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans