Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

InMemory table as datasource in the form could not read existing records on Initvalue() method.

Posted on by Microsoft Employee

Hello,

I have a simple form  where it has a  table (In Memory) as a datasource.

On page load, I m filling this table from data coming from web services on the fly. 

Once page gets loaded, User adds a new record in it. For each line user adds, i want to assign the new Line num which would be in addition to the max linenum out of the record i got from the web service records.

Hence in Initvalue() method of table, I am trying to find the max linenum from the existing record but I always get 0 records. not sure why.  User could see the records came from the web service on the form. They can add the new record as well but LineNum is not getting set correctly for these new records. ALL newly added records gets LineNum=1 because it thinks that there is no any record in the table.

Table's initvalue method is shown below.

public void initValue()
{

MyTempTable  tmp;

super();

select maxOf(LineNum) from tmp;
this.LineNum = tmp.LineNum +1;
 
}

Can someone help to identify what's missing?

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: InMemory table as datasource in the form could not read existing records on Initvalue() method.

    Instead of writing code in initvalue() of table, i wrote it on initvalue() of form datasource and it worked. I wrote it before super() call in it.

    public void initValue()

    {

    MyTempTable  tmp;

    tmp.settmpData(MyTempTable);  // Here MyTempTable is a datasource.

    select maxOf(LineNum) from tmp;

    this.LineNum = tmp.LineNum +1;

    super();

    }

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: InMemory table as datasource in the form could not read existing records on Initvalue() method.

    setTmpData should actually work, could you please share your code, so we can advise if something wrong there.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: InMemory table as datasource in the form could not read existing records on Initvalue() method.

    I already tried this but somehow forgot to mention in my question.  Sorry that doesn't work.

  • Suggested answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,786 on at
    RE: InMemory table as datasource in the form could not read existing records on Initvalue() method.

    Temporary tables, both memory and tempdb, are not backed by single instance table like regular AOT tables.  With regular AOT tables, like CustTable, when you declare a variable of type CustTable, it is ultimately backed by the same physical database table.  You can select and filter on your variable, creating a result set (or subset), and move next and such, acting as a cursor, but all variables of type CustTable share a common backing table.

    Each time you instance a temporary table, as you have done in your declarations in initValue(), it is backed by a separate data set.  So in your initValue() method when you declare MyTempTable tmp; that is not the same backing table as the record referenced by "this".

    Fortunately, you can connect your new variable to the backing table of "this".  I believe the following line works (it is different for in memory and tempdb tables).

    tmp.setTmpData(this);

    Hope this helps.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans