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

Free text invoice Lines are duplicating each time i click on OK btn for credit invoicing - D365FO

(1) ShareShare
ReportReport
Posted on by 404
Hi, im facing an issue with invoice lines in FTE form.
when i create a new customer and wants to add new credit invoicing, its coming correct for first time.
////
 
Now if i click again on the credit invoicing and click on OK again, the line will be duplicated.
here is my code:
----
[ExtensionOf(formControlStr(CustVendCreditInvoicing, OK))]
final class CustVendCreditInvoicing_Ok_Extension
{
    public void clicked()
    {
        Common                           callerTable1;
        CustInvoiceTable                _custInvoiceTableOld, custInvoiceNew;
        CustInvoiceLine                 _custInvoiceLineOld, _custLineNew;

        FormRun formRun;
        callerTable1 = element.args().record();
        formRun = element.args().caller();
        FormStringControl _cntrStr = this.formRun().design().controlName(/CustVendCorrectedInvoiceId/);
        str invoiceid = _cntrStr.text();
      
        next clicked();
        if(callerTable1.TableId == tablenum(CustInvoiceTable))
        {
            custInvoiceNew = callerTable1;
        }
        ttsbegin;
            select  _custInvoiceTableOld where _custInvoiceTableOld.InvoiceId == invoiceid;
            custInvoiceNew.DocumentDate = _custInvoiceTableOld.DocumentDate;
            custInvoiceNew.ReleaseDate = _custInvoiceTableOld.ReleaseDate;
            custInvoiceNew.InclTax = _custInvoiceTableOld.InclTax;
            custInvoiceNew.WorkerSalesTaker = _custInvoiceTableOld.WorkerSalesTaker;
            custInvoiceNew.CustomerRef = _custInvoiceTableOld.CustomerRef;
            custInvoiceNew.ContactPersonId =  _custInvoiceTableOld.ContactPersonId;
            custInvoiceNew.Payment = _custInvoiceTableOld.Payment;
            custInvoiceNew.PaymMode = _custInvoiceTableOld.PaymMode;
            custInvoiceNew.CustBankAccountId = _custInvoiceTableOld.CustBankAccountId;
            custInvoiceNew.PaymentSched = _custInvoiceTableOld.PaymentSched;
            custInvoiceNew.CashDiscCode = _custInvoiceTableOld.CashDiscCode;
            custInvoiceNew.DirectDebitMandate = _custInvoiceTableOld.DirectDebitMandate;
            custInvoiceNew.DefaultDimension = _custInvoiceTableOld.DefaultDimension;

           custInvoiceNew.update();
        ttscommit;
        ttsbegin;
        while select _custInvoiceLineOld where _custInvoiceLineOld.ParentRecId == _custInvoiceTableOld.RecId
        {
            _custLineNew.clear();
            _custLineNew.initValue();
            _custLineNew.ParentRecId = custInvoiceNew.RecId;
            _custLineNew.Description =_custInvoiceLineOld.Description;
            _custLineNew.LedgerDimension = _custInvoiceLineOld.LedgerDimension;
            _custLineNew.TaxGroup = _custInvoiceLineOld.TaxGroup;
            _custLineNew.TaxItemGroup = _custInvoiceLineOld.TaxItemGroup;
            _custLineNew.TaxWithholdGroup = _custInvoiceLineOld.TaxWithholdGroup;
            _custLineNew.TaxWithholdItemGroupHeading_TH =_custInvoiceLineOld.TaxWithholdItemGroupHeading_TH;
            _custLineNew.Quantity = - _custInvoiceLineOld.Quantity;//negataive value
            _custLineNew.UnitPrice = _custInvoiceLineOld.UnitPrice;
            _custLineNew.AmountCur = - _custInvoiceLineOld.AmountCur;//negative value
            _custLineNew.DefaultDimension = _custInvoiceLineOld.DefaultDimension;
            _custLineNew.insert();
        }
        ttscommit;
      
        if(formrun)
        {
            formrun.doResearch(); // Force all parent form data sets to refresh
        }
    }
}
 
any idea how to fix this issue?
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    17,377 Super User 2025 Season 1 on at
    Free text invoice Lines are duplicating each time i click on OK btn for credit invoicing - D365FO
    Hi,
     
    I can't understand the logic of your code exactly, but I think you can use write() instead of Insert() method
    _custLineNew.write();
     
    Best regards,
    Mohamed Amine MAHMOUDI

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February 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... 293,150 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans