web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Type of variable in declaration

(0) ShareShare
ReportReport
Posted on by

I want to find out the type of a variable's name which is a string. There probably must be a function like this, but I cannot find it.

I expect to work it like this:

str input;

anytype result;

;

input = "SysSetup";

result = function(input); // returns "class", probably string or enum

input = "AgreementReference";

result = function(input); // returns "table"

input = "ABC";

result = function(input); // returns "base enum"

etc.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Maybe you can use

    typeOf(yourvariable)

  • Community Member Profile Picture
    on at

    Thanks, but it doesn't work.

    If typeof function recieves string, it returns "String". If it would be possible to convert this string to Object and get type of that object, then it would probably work.

  • Verified answer
    Jesus R. ABASCAL Profile Picture
    1,450 on at

    You can use utilelements table as follow:

    #AOT

       UtilElements        utilElements;

       UtilIdElements      utilIdElements;

       DictField           df;

       DictTable           dt;

       TreeNode            tn;

       int                 counter = 0;

       while

           select      utilElements

           where       utilElements.name == "SysSetup"

       {

           info(strFmt("%1",utilElements.recordType));          

       }

  • Jonathan  Halland Profile Picture
    11,310 on at

    Hi.

    There seem to be a few flaws in your question.

    1. Your code seems to want to actually instantiate the type to a variable rather than simply retrieve the name of the type (which would typically be a string)

    2. It seems like you want to figure out the type from a simple Name. This is illogical as there can be different objects in the AOT with the same name. E.G. Forms can have the same names as classes or tables.

    Can you maybe expand on what you would like to do?

  • Verified answer
    Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    I think I finally got what you're trying to do. I would simply look into modelstore:

    public static UtilElementType getElementType(UtilElementName _name)
    {
        SysModelElement modelElement;
        UtilElementType elementType;
        
        select ElementType from modelElement
            where modelElement.Name == _name
               && ( modelElement.ElementType == UtilElementType::Table
                 || modelElement.ElementType == UtilElementType::Class
                 || modelElement.ElementType == UtilElementType::ExtendedType
                 || modelElement.ElementType == UtilElementType::Enum);
        
        elementType = modelElement.ElementType;
              
        return elementType;
    }
    
    // Usage
    info(enum2str(Test::getElementType('SysSetup')));
  • Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    It works all right as long as it's restricted to types, because there can't be two types with the same name. Forms, for example, aren't types and can't be used in variable declaration.

  • Jonathan  Halland Profile Picture
    11,310 on at

    Thanks Martin.

    I see now they did explicitly talk about a variable's type. I just included that comment as additional info just in case.

  • Community Member Profile Picture
    on at

    Yes, Jesus, thank you. I didn't thought of it.

  • Community Member Profile Picture
    on at

    Thank you, Martin!

    That's a great function.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans