Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Problem with inserting into a table

(0) ShareShare
ReportReport
Posted on by 737
Hello,
I extended the SalesPackingSlipJournalCreate.initJournalLine() method so that when I create journal lines, I create records in a custom myTable that is used to create a custom report.
Everything seems to work OK, and I can run the report. The report runs, but the DP class does not show the previously created record in myTable. The previously created record is not yet available (I execute select query on this table) and cannot be retrieved from myTable. Only after the report is generated (either empty or with wrong data) does the previously inserted record appear in myTable.
How to solve this problem? Because I understand that after insert() the record should already be available in the table.
Thank you.
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 7,177 Super User 2025 Season 1 on at
    Problem with inserting into a table
     
    Your table is Shared or not ? If it is not share, can you double check if it is inserted on the right company?
    As I see you use cross company on the code and you have many companies.
     
     
    Regards,
    Waed Ayyad
     
     
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
     
     
  • Shooowtek Profile Picture
    Shooowtek 737 on at
    Problem with inserting into a table
    My table is inserted in the method SalesPackingSlipJournalCreate.initJournalLine():
    public Common initJournalLine(Common _parmLine)
        {
            CustPackingSlipTrans localcustPackingSlipTrans;
      
            localcustPackingSlipTrans = next initJournalLine(_parmLine);
     
            if(!localcustPackingSlipTrans.PackingSlipId)
            {
                this.insert2myTable(localcustPackingSlipTrans);
            }
            return localcustPackingSlipTrans;
        }
     
    public void insert2myTable(CustPackingSlipTrans _custPackingSlipTrans)
        {
            itemId itemId = _custPackingSlipTrans.ItemId;
            packingSlipId packingSlipId   = _custPackingSlipTrans.PackingSlipId;
            InventTrans inventTrans;
            InventTransOrigin InventTransOrigin;
            container companies_con;
            inventBatchId inventBatchId;
            prodTable prodTable;
            bomId bomId;
            MyTable myTable;
            companies_con = conins(companies_con, 1, curext());
            if (itemId && InventTable::find(itemId).isFormulaOrBOMAllowed())
            {
                while select inventTrans group by inventTransOrigin, inventDimId, itemId, voucherPhysical
                    //where inventTrans.VoucherPhysical == packingSlipId
                join InventTransOrigin
                    where InventTransOrigin.recid == inventTrans.inventtransorigin
                    && InventTransOrigin.InventTransId == _custPackingSlipTrans.InventTransId
                {
                    inventBatchId = InventDim::find(inventTrans.InventDimId).inventBatchId;
                    select firstonly crosscompany: companies_con prodTable
                        where prodTable.ProdId == inventBatchId;
                    if(prodTable)
                    {
                        bomId    = ProdTable.BOMId;
                        itemId   = ProdTable.ItemId;
                    }
                }
                
                myTable.inventBatchId = inventBatchId;
                myTable.InventTransId = _custPackingSlipTrans.InventTransId;
                myTable.ItemId = itemId;
                myTable.bomId = bomId;
                myTable.insert();
            
     
    My report is run by calling menuitem, in the SalesPackingSlipDP.initializeSalesPackingSlipLine() method, because it is supposed to display along with the SalesPackingSlip report, for each custPackingSlipTrans record.
    /***/
                    MenuFunction menuFunction = new MenuFunction(MenuItemOutputStr(myReportMenuItem),MenuItemType::Output);
                    Args args = new Args();
                    args.caller(this);
                    args.record(bomtable);
                    menuFunction.run(args);
    /***/
     
    Example. If a user runs a SalesPackingSlip report that contains two custPackingSlipTrans records. Finally, three printouts appear on the screen. 1 x SalesPackingSlip and 2 x myCustomReport
  • Suggested answer
    Problem with inserting into a table
    Hi,

    1. From the code snippet that you shared, assuming this is the code you are running with, I can see that you insert into your custom table when you do not have a PackingSlipId.
    However, this PackingSlipId is being used again in your insert method. Is this intended?
     
    2. Can you elaborate more on the statement again because its not clear for me and maybe for some others as well.

    BR,
    Ozair
     
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 7,643 Super User 2025 Season 1 on at
    Problem with inserting into a table
    Hi Shooowtek,
     
    I'm trying to help here but please answer the questions. The reason I asked if Table.RecId is filled after the insert in the debugger watch or not is because if it's empty then maybe there is a bigger transaction(ttsbegin, ttscommit) that is delaying the insert and that's another reason why I asked for full code in case we are missing sth.
     
    Maybe Try to put ttsbegin and ttscommit 
    ttsbegin;
    //
    Table.insert();
    ttscommit;
     
    And let us know if it works.
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Shooowtek Profile Picture
    Shooowtek 737 on at
    Problem with inserting into a table
    OK, I understand your questions, but according to me everything should work properly. I don't know why, but the insertion happens only after the whole code is executed. I just debugged this and after going one step after myTable.insert(), I checked this table through SQL Server Management and it was empty the whole time. Only when I "continue" in the debugger did the record appear in the table. That is, it seems that the insert performs after passing all the code.
    This is a bit strange to me. Does anyone know what I am doing wrong?
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 7,643 Super User 2025 Season 1 on at
    Problem with inserting into a table
    Hi Shooowtek,

    Can you please share with us the whole code then?

    Also can you check the debug after myTable.Insert() directly by looking at watch maybe? Is the recId filled for this table or not?
    ​​​​​​​
    The reason why i want to see the whole code is because if you define a buffer then select it without a where condition, then it will always be empty â€‹â€‹â€‹â€‹â€‹â€‹â€‹ -- maybe this will give you a hint
     
    So I'm not sure also what do you mean by this "Only after the report is generated (either empty or with wrong data) does the previously inserted record appear in myTable"
    Do you mean if you try to generate the report manually? not through code?


    Thanks,
    Layan Jweihan
    ​​​​​​​Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Shooowtek Profile Picture
    Shooowtek 737 on at
    Problem with inserting into a table
    I run the report via code, using the item menu call.
     
    /***/
                    MenuFunction menuFunction = new MenuFunction(MenuItemOutputStr(myReportMenuItem),MenuItemType::Output);
                    Args args = new Args();
                    args.caller(this);
                    args.record(bomtable);
                    menuFunction.run(args);
    /***/

    And theoretically it is entered where myTable.insert() should have already been executed.
  • Layan Jwei Profile Picture
    Layan Jwei 7,643 Super User 2025 Season 1 on at
    Problem with inserting into a table
    Hi Shoowetek,

    You didn't answer this question: "Does the report run after you insert? or the code stops at inserting. Then you go to a button to run the report?"
    I mean when does the initJournalLine gets called and when does you report get run. 
    I mean do you open the report by code after you insert. Or when then insert is done. You go to a menu item and run the report?
     
    Thanks,
    Layan Jweihan

     
  • Shooowtek Profile Picture
    Shooowtek 737 on at
    Problem with inserting into a table
    myTable table is not a data source for the report. The idea is to make select  query on myTable based on the data received from the query, and then put it in the tmp table, which is the data source for this report.
    MyTable is a regular table.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans