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 :
Finance | Project Operations, Human Resources, ...
Suggested answer

Problem with inserting into a table

(0) ShareShare
ReportReport
Posted on by 843
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.
I have the same question (0)
  • Suggested answer
    Waed Ayyad Profile Picture
    8,972 Super User 2025 Season 2 on at
    Problem with inserting into a table
     
    Are you sure the data is filled on your custom table (you can try to debug it and see if the data is saved or not), also you can try to debug your DP class and see if the values are coming or not.
     
    You can use this link to debug your DP code.
     
     
     
    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
    843 on at
    Problem with inserting into a table
    Hi,
     
    Yes, I have debugged many times before and it is as I wrote above. The data is inserted into the table, and when I do a select query in the DP class it does not find the data.... 
  • Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 on at
    Problem with inserting into a table
    Hi Shooowtek,

    Can you share with us your code in SalesPackingSlipJournalCreate.initJournalLine() and the RDP class.

    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
    843 on at
    Problem with inserting into a table
    /* extension of SalesPackingSlipJournalCreate.initJournalLine() */
    public Common initJournalLine(Common _parmLine)
        {
            CustPackingSlipTrans localcustPackingSlipTrans;
      
            localcustPackingSlipTrans = next initJournalLine(_parmLine);
     
            if(!localcustPackingSlipTrans.PackingSlipId)
            {
                this.insert2myTable(localcustPackingSlipTrans);
            }
            return localcustPackingSlipTrans;
        }
     
    /* insert2myTable method */
    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();
            }
        }
     
    /* DP class sample, with select query  - processReport method */
     
    /***/
            MyTable myTable;  
            itemId itemId;
            inventBatchId inventBatchId;
    /***/
            qr  = new QueryRun(this.parmQuery());
            query = this.parmQuery();
            qbds = query.dataSourceTable(tableNum(BomTable));
            qbr = qbds.findRange(fieldnum(BomTable, BOMId));
            BOMId = qbr.value();

            select firstonly myTable; 
            // I select any record from the table, unfortunately none was ever found, even though the insert() function was called earlier in the method
            
            if(myTable)
            {
                InventBatchId = myTable.inventBatchId;
                ItemId = myTable.ItemId;
            }
    /***/
  • Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 on at
    Problem with inserting into a table
    Hi Shooowtek,
     
    What is the table type? is it regular to tmpDB?
    And does the report runs after you insert? or the code stops at inserting. Then you go to a button to run the report?
    Last question, you said "The previously created record is not yet available"    do you mean the report that you run is empty?
     
    Also can you please share with the us the whole RDP code?
    do you have this method inside it??

        [SrsReportDataSetAttribute('MyTable')]
        public MyTable getiveMyTable)
        {
            select myTable;
            return myTable;
        }


     
    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
    843 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.
  • Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 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
    843 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.
  • Suggested answer
    Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,771

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 806 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 542 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans