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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Dynamic queries

(0) ShareShare
ReportReport
Posted on by 125

I've a table ID and I need to query aseveral fields and methods on this Table. It is all dynamic, both the table Id and the list of fields and methods.

What is the best way to get the needed table information.

Thanks & Happy New Year

*This post is locked for comments

I have the same question (0)
  • Joris dG Profile Picture
    17,775 on at
    Re: Dynamic queries

    To get table information (metadata), you can use the Dict* classes...

    So start with DictTable class, which can get you dictfield, dictindex, dictmethod, etc...

  • Suggested answer
    Amir Nazim Profile Picture
    5,994 on at
    Re: Dynamic queries

    Hi,

    addition on answer.

    you will find methods in DictTable class to access the fields, methods, properties, indexes etc of any table based on TableId

    Inorder to select the record you need to use the simple code below

       Common common;
       DictTable dictTable = new DictTable(_tableId);
       ;
       common = dictTable.makeRecord();
       select firstonly  common;

    InOrder to access any field from filled common buffer, use simple code below

       print common.(fieldNum(LedgerPeriod, PeriodStart));

    Thanks
    Amir
    https://msdax.wordpress.com

  • Oren Ben-Meir Profile Picture
    125 on at
    Re: Dynamic queries

    Thanks for your replies.

    I see how to get a field that is part of the table but how can I get a display method value?

    How can I invoke the method dynamically?

  • Amir Nazim Profile Picture
    5,994 on at
    Re: Dynamic queries

    Hi,

    This is prety easy to you can call the table level method using method
    public anytype callObject(...)


    Here the example excerpt from the dynamics ax documentation

    {
        Dicttable         dictTable;
        int               onlineTime;
        Common            common;
        str               resultOutput;
        ExecutePermission perm;
        ;
       
        perm = new ExecutePermission();
        dictTable= new DictTable(tablenum(SysUserLog));
        if (dictTable != null)
        {
            common = dictTable.makeRecord();
     
            // Grants permission to execute the
            // DictTable.callObject method. DictTable.callObject runs
            // under code access security.
            perm.assert();
     
            onlineTime   = dictTable.callObject("onlineTime", common);
            resultOutput = strfmt("User online time is %1", onlineTime);
            print resultOutput;
            pause;
        }
       
        // Close the code access permission scope.
        CodeAccessPermission::revertAssert();
    }

    Thanks
    Amir
    https://msdax.wordpress.com

     

     

  • Verified answer
    Amir Nazim Profile Picture
    5,994 on at
    Re: Dynamic queries

    Hi,

    This is prety easy to you can call the table level method using method
    public anytype callObject(...)


    Here the example excerpt from the dynamics ax documentation

    {
        Dicttable         dictTable;
        int               onlineTime;
        Common            common;
        str               resultOutput;
        ExecutePermission perm;
        ;
       
        perm = new ExecutePermission();
        dictTable= new DictTable(tablenum(SysUserLog));
        if (dictTable != null)
        {
            common = dictTable.makeRecord();
     
            // Grants permission to execute the
            // DictTable.callObject method. DictTable.callObject runs
            // under code access security.
            perm.assert();
     
            onlineTime   = dictTable.callObject("onlineTime", common);
            resultOutput = strfmt("User online time is %1", onlineTime);
            print resultOutput;
            pause;
        }
       
        // Close the code access permission scope.
        CodeAccessPermission::revertAssert();
    }

    Thanks
    Amir
    https://msdax.wordpress.com

     


     

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
Priya_K Profile Picture

Priya_K 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans