Skip to main content

Notifications

Announcements

No record found.

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

Is it possible to get the the data type of the method that is returning?

Posted on by Microsoft Employee

Hello Every One,

Is it possible to get the the data type of  the method that is returning? Like I have a table method that is returning boolean using x++ how do i get it ? Even if their return type is an edt also would like to get the data type of it as well?

Same like for table fields we are are able to get it using dictfield.baseType().

Is there any way that I can get it?

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 the data type of the method that is returning?

    static void Es_getReturnBaseType(Args _args)
    {
        SysDictTable    dictTable = new SysDictTable(tableNum(SalesLine));
    
        SysDictMethod   dictMethod;// = new SysDictMethod(UtilElementType::TableStaticMethod, tableNum(SalesLine), tableMethodStr(SalesLine, amountCur));
        DictType        dictType;
        DictEnum        dictEnum;
        Types           type;
        int             typeId;
        int             i;
        
        str extendedTypeId2BaseName(Types _type, int _typeId)
        {
            switch (_type)
            {
                case Types::String:
                case Types::RString:
                case Types::VarString:
                    return 'str';
                case Types::Container:
                    return 'container';
                case Types::Class:
                    return classId2Name(_typeId) ? classId2Name(_typeId) : classStr(Object);
                case Types::UserType:
                    dictType = new DictType(_typeId);
                    return strFmt("%1",dictType.baseType());
                case Types::Record:
                    return tableId2name(_typeId);
                case Types::Real:
                    return 'real';
                case Types::Date:
                    return 'date';
                case Types::Time:
                    return 'time';
                case Types::UtcDateTime:
                    return 'utcdatetime';
                case Types::AnyType:
                    return 'anytype';
                case Types::void:
                    return 'void';
                case Types::Integer:
                    return 'int';
                case Types::Int64:
                    return 'int64';
                case Types::Enum:
                    return 'base enum';
                case Types::Guid:
                    return 'guid';
            }
            return '';
        }
        for (i=1; i<=dictTable.objectMethodCnt(); i  )
        {
            dictMethod  = dictTable.objectMethodObject(i);
            type        = dictMethod.returnType();
            typeId      = dictMethod.returnId();
                
            info('Method name:'   dictMethod.name()   "-"   'Return type:'    extendedTypeId2DisplayName(type,typeId)    "-"   'Base type:'   extendedTypeId2BaseName(type,typeId) );
        }
    }

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Is it possible to get the the data type of the method that is returning?

    There is code to find the return EDT - I told you which method to use (SysDictMethod.returnId()) and Ergün then gave you sample code.

    If you have a problem with it, please explain the problem in the original thread.

    If you just ask the same question, all we could do is giving you the same answer.

    Note that I don't understand the sentence "I am which type that is extended in edt". If it was going to say something important, please rephrase it.

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Is it possible to get the the data type of the method that is returning?

    There is code to find the return EDT - I told you which method to use (SysDictMethod.returnId()) and Ergün then gave you sample code.

    If you have a problem with it, please explain the problem in the original thread.

    If you just ask the same question, all we could do is giving you the same answer.

    Note that I don't understand the sentence "I am which type that is extended in edt". If it was going to say something important, please rephrase it.

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Is it possible to get the the data type of the method that is returning?

    There is code to find the return EDT - I told you which method to use (SysDictMethod.returnId()) and Ergün then gave you sample code.

    If you have a problem with it, please explain the problem in the original thread.

    If you just ask the same question, all we could do is giving you the same answer.

    Note that I don't understand the sentence "I am which type that is extended in edt". If it was going to say something important, please rephrase it.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to get the the data type of the method that is returning?

    Hi Martin,

    In the above thread there is no code to find the Extended data type type. I am which type that is extended in edt. So instead of asking in the previous thread I created new one.

    Thanks,

    Phani

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Is it possible to get the the data type of the method that is returning?

    You've already got answers in your previous thread, "Is it possible to get the method return type in Ax2012?" (community.dynamics.com/.../is-it-possible-to-get-the-method-return-type-in-ax2012). Please read them. If you have a follow-up question, ask it there, rather then creating a duplicate thread about the same thing and starting the whole discussion from the very beginning, as if you never read any answers.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to get the the data type of the method that is returning?

    Hi Hossein Karimi,

    It seems my question itself not clear to you.

    Eg1:  

    public boolean valid()

    {

    // some code here

    }

    eg 2:

    public Amount Price()

    {

    // some code here

    }

    from the eg1 I have to take boolean. and in eg 2 Amount is Extended data type in turn which gives Real data types .

    I want to get thoes two data types and show in info log.

    Thanks,

    Phani

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: Is it possible to get the the data type of the method that is returning?

    Hi,

    I said you can develop a method and in this method write a switch case and check all state with the method which I sent you.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Is it possible to get the the data type of the method that is returning?

    Hi Hossein Karimi ,

    Thanks for your reply.

    I am not talking about the value that the method return. when we look at the method code we understand the return type of it. I just want to write some x++ code to pull it. is it possible?

    Thanks,

    Phani

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: Is it possible to get the the data type of the method that is returning?
    Informational functions isbool(X) Returns TRUE if the field value is Boolean.
    isint(X) Returns TRUE if the field value is an integer.
    isnotnull(X) Returns TRUE if the field value is not NULL.
    isnull(X) Returns TRUE if the field value is NULL.
    isnum(X) Returns TRUE if the field value is a number.
    isstr(X) Returns TRUE if the field value is a string.
    typeof(X) Returns a string that indicates the field type, such as Number, String, Boolean, and so forth

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans