Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

copy multipel sales order from SalesParmTable

Posted on by 52
Hello everyone.
I need to duplicate the sales orders (from SalesParmTable) for which the user is generating a proforma for a certain project, and then I need to re-insert those sales orders in SalesParmtable once the proforma has been created.
below is my code 
//Hold the SalesParmTable record         protected void endParmUpdate()    {        SalesParmTable salesParmTableCopy;        SalesParmTable salesParmtable;        SalesParmLine  salesParmLineCopy;        SalesParmLine  salesParmLine;        SalesParmUpdate salesParmUpdate;        RecordInsertList list = new RecordInsertList(tablenum(SalesParmLine));        RecordInsertList listSalesParmTable = new RecordInsertList(tablenum(SalesParmTable));        formletterParmUpdate   formletterParmUpdate = this.formletterParmUpdate;        FormletterParmTable     formletterParmTable = this.formletterParmTable;               if (formletterParmUpdate.TableId != tableNum(FormletterParmUpdate)) //Ensure that the map is initialized        {                        ttsbegin;            select firstonly forupdate formletterParmUpdate                where formletterParmUpdate.ParmId == parmId;                       select salesParmUpdate                where salesParmUpdate.ParmId == parmId;              if (formletterParmUpdate)            {                if (this.canDeleteFormletterUpdate() && this.proforma && salesParmUpdate.xxProFormaInvoiceNumber == NoYes::Yes)                {                   while select salesParmtable order by SalesId                        where salesParmtable.ParmId == parmId                    {                        salesParmTableCopy.data(salesParmtable);                        listSalesParmTable.add(salesParmTableCopy);                        while select * from salesParmLine                            where salesParmtable.ParmId == salesParmLine.ParmId                            && salesParmtable.TableRefId == salesParmLine.TableRefId                        {                            salesParmLineCopy.data(salesParmLine);                            list.add(salesParmLineCopy);                        }                    }                }                          }            ttscommit;        }                    next endParmUpdate();        if (formletterParmUpdate.TableId != tableNum(FormletterParmUpdate)) //Ensure that the map is initialized gg        {            ttsbegin;                   if (formletterParmUpdate)            {                if (this.canDeleteFormletterUpdate() && this.proforma && salesParmUpdate.xxProFormaInvoiceNumber == NoYes::Yes)                {                    salesParmTableCopy.selectForUpdate(true);                    //salesParmTableCopy.insert();                    listSalesParmTable.insertDatabase();                    list.insertDatabase();                    salesParmTableCopy.reread();                }            }            ttscommit;        }    }
The issue is that, despite their being several records with the parmId, I always get just one record from SalesParmTable.
Any kind of help would be very much appreciated.
  • Community member Profile Picture
    Community member 52 on at
    copy multipel sales order from SalesParmTable
    I selected multiple sales orders to use to generate a proforma. Upon opening the SalesEditLine, I saw that those identical sales orders have the same parmId in the SalesParmTable.
    It seems like they were deleted before I ran my code because all I get when I try to copy them is only one sales order.
  • Martin Dráb Profile Picture
    Martin Dráb 229,275 Most Valuable Professional on at
    copy multipel sales order from SalesParmTable
    What exactly do you mean by "I picked multiple sales orders"?
     
    Also, are you saying that you expect mutiple SalesParmTable records created by they aren't, or they're deleted before you run your code? If you don't know, use the debugger to find it out.
     
     
  • Community member Profile Picture
    Community member 52 on at
    copy multipel sales order from SalesParmTable
    Hello Martin You are correct, even though I picked multiple sales orders, there is only one sales order when I check with SQL.
    i tried my code in SalesInvoiceJournalPost endUpdate() but with the same result.
    my task is When a user creates a proforma, is to copy every line in the header (SalesParmTable) and every line in the SalesParmLine when a user creates a proforma, and re-insert it when the SalesEditLines form is closed.
  • Martin Dráb Profile Picture
    Martin Dráb 229,275 Most Valuable Professional on at
    copy multipel sales order from SalesParmTable
    If I understand it correctly, this is the code you're struggling with.
    [ExtensionOf(classStr(FormletterService))]
    final class MyFormletterService_Extension
    
    protected void endParmUpdate()
    {
        SalesParmTable salesParmTable;
    
        while select salesParmTable
            where salesParmtable.ParmId == parmId
        {
            info(salesParmTable.SalesId);
        }
    
        next endParmUpdate();
    }
    The rest of code isn't relevant in this case and therefore it would just distract us from the current issue.
     
    How did you verify that there multiple records in database for the given parm ID and company at that time? Did you, for example, stop execution on breakpoint and run a SQL query without transaction isolation? I doubt you'd get a different result then from X++.
     
    Putting your code FormletterService sounds wrong to me. It's a generic class for all postings for both purchase and sales, while your code is clearly just for sales and likely just for a particular type of posting (invoice). If so, you should use a class for invoice posting of sales orders, such as SalesInvoiceJournalPost.
  • Community member Profile Picture
    Community member 52 on at
    copy multipel sales order from SalesParmTable

    Hello Martin I thank you for your quick reply, i have extended the FormletterService.
    When I debug, I can see that I have the correct parmId, but SalesParmTable does not loop through; instead, it appears as though there is just one record, even though there are multiple records with that parmId when I check SalesParmTable.

     i can finally reply but i can't insert any code.

    //Hold the SalesParmTable record 
            protected void endParmUpdate()
        {
            SalesParmTable salesParmTableCopy;
            SalesParmTable salesParmtable;
            SalesParmLine  salesParmLineCopy;
            SalesParmLine  salesParmLine;
            SalesParmUpdate salesParmUpdate;
            RecordInsertList list = new RecordInsertList(tablenum(SalesParmLine));
            RecordInsertList listSalesParmTable = new RecordInsertList(tablenum(SalesParmTable));
            formletterParmUpdate   formletterParmUpdate = this.formletterParmUpdate;
            FormletterParmTable     formletterParmTable = this.formletterParmTable;
           
            if (formletterParmUpdate.TableId != tableNum(FormletterParmUpdate)) //Ensure that the map is initialized
            {
                
                ttsbegin;
                select firstonly forupdate formletterParmUpdate
                    where formletterParmUpdate.ParmId == parmId;
               
                select salesParmUpdate
                    where salesParmUpdate.ParmId == parmId;
      
                if (formletterParmUpdate)
                {
                    if (this.canDeleteFormletterUpdate() && this.proforma && salesParmUpdate.xxProFormaInvoiceNumber == NoYes::Yes)
                    {
                       while select salesParmtable order by SalesId
                            where salesParmtable.ParmId == parmId
                        {
                            salesParmTableCopy.data(salesParmtable);
                            listSalesParmTable.add(salesParmTableCopy);
                            while select * from salesParmLine
                                where salesParmtable.ParmId == salesParmLine.ParmId
                                && salesParmtable.TableRefId == salesParmLine.TableRefId
                            {
                                salesParmLineCopy.data(salesParmLine);
                                list.add(salesParmLineCopy);
                            }
                        }
                    }              
                }
                ttscommit;
            }
            
        
            next endParmUpdate();
            if (formletterParmUpdate.TableId != tableNum(FormletterParmUpdate)) //Ensure that the map is initialized gg
            {
                ttsbegin;
           
                if (formletterParmUpdate)
                {
                    if (this.canDeleteFormletterUpdate() && this.proforma && salesParmUpdate.xxProFormaInvoiceNumber == NoYes::Yes)
                    {
                        salesParmTableCopy.selectForUpdate(true);
                        //salesParmTableCopy.insert();
                        listSalesParmTable.insertDatabase();
                        list.insertDatabase();
                        salesParmTableCopy.reread();
                    }
                }
                ttscommit;
            }
        }

  • Martin Dráb Profile Picture
    Martin Dráb 229,275 Most Valuable Professional on at
    copy multipel sales order from SalesParmTable
    Please paste your code once more in a reply; this site has a bug causing formatting problems in the first post.
     
    Then tell us which class you extended and what you found when you debugged your code before giving up and asking here.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,275 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans