Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Loading and selecting from an in-memory table

(0) ShareShare
ReportReport
Posted on by 70

Dear Dynamics community,

I could use your assistance completing an issue I'm having when attempting to load a temporary in-memory table from a List.
The behavior that I've noticed is that when I set the temporary table I'm only able to load a single object from the list; when I attempt to load multiple objects an error is thrown (as I would expect the List to be dynamic, and more than two objects in the list will typically be expected).  Is there a method or process where I might load multiple objects of the same type into a temporary table on which to perform a select from?

Currently my code is set up as follows:

private BRKContractHeader finalListReduction(List contracts)
    {
        BRKContractHeader bestContract;
        BRKContractLine bestContractLine;
        BRKShippingScenario bestShippingScenario;
        bestContract.setTmp();

        ListEnumerator enumerator = contracts.getEnumerator();

        while(enumerator.moveNext())
        {
            BRKContractHeader header = enumerator.current();

            bestContract.setTmpData(header);
            bestContract.doInsert();
        }

Furthermore the method continues and I attempt a 'select' against the existing information I expect to be loaded into the temp table:

select bestContract
            join bestContractLine 
            join bestShippingScenario 
        order by bestContract.ContractId desc
            , bestContractLine.ContractLine desc
            , bestShippingScenario.ShippingScenarioLine desc
        where bestContract.ContractId == bestContractLine.ContractId
            && bestContract.ContractId == bestshippingScenario.ContractId
            && bestContractLine.ContractLine == bestShippingScenario.ContractLine
            && bestContractLine.FreightResponsibility == BRKFreightResponsibility::DJJ
        {
            bestContract = bestContract;   
        }

        
        return bestContract;
    }

Ideally I would like to be able to load multiple records into the header table, find the corresponding line and shippingScenarios information, in order to whittle down the list to where only a few (ideally one) contract would remain.

Your help, as always, is much appreciated.  Happy St. Valentine's Day to you all!

  • delarosaau Profile Picture
    70 on at
    RE: Loading and selecting from an in-memory table

    Quick update: buf2Buf() seems to be fix for getting the data into the temp table as I might expect.  My other issue was self-induced: I was sloppy about handling class-level variables and my main error issue was, in fact, that I had multiple records with the exact same recIds being inserted into the table, THAT was the main culprit of my issues.

    Lessons learned.  Thanks for your input Martin, as well as Gunjan and others.  Still in the process of sorting through my other issues but will report any new findings as they show their heads.

    Best,

    Austin

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Loading and selecting from an in-memory table

    Please check this post to check how setTmpData() works. In your case, you can use buf2buf as Martin mentioned and can call bestContract.insert() to insert into the temporary table.

  • delarosaau Profile Picture
    70 on at
    RE: Loading and selecting from an in-memory table

    The 'error' that occurs is when the second record is attempting to be loaded the loop will kick on the insert() and cease further operations.  If I recall during doInsert() the first record is overwritten.  I believe setTmpData() has the same behavior as insert(), exiting the loop and all following code.

    Working in a class currently.  And thanks for the tip on buf2buf(); will give it a whirl and report back.

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Loading and selecting from an in-memory table

    Like Martin said you can use buf2buf and insert record but When you use below code.

    "bestContract.data(header.data());"

    What error you are getting?

    Are you working on form?

  • Verified answer
    Martin Dráb Profile Picture
    233,017 Most Valuable Professional on at
    RE: Loading and selecting from an in-memory table

    What if you use buf2buf() method to copy data between bestContract and header?

    By the way, what does the error message say?

  • delarosaau Profile Picture
    70 on at
    RE: Loading and selecting from an in-memory table

    Only reason I had tried using setTmpData method is because I was getting errors when using the .data() method when attempting to load multiple records into the temp table, simply the last iteration of my attempts at fixing what wasn't working.  Happy to hear how you recommend to instantiate, fill, and access the temp table records.  Thanks!

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Loading and selecting from an in-memory table

    Hi delarosaau,

    Could you please explain why you are calling the "setTmpData" method? You are creating a new instance link to the last record instantiated in the List.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans