web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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 406
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
    26,826 Super User 2026 Season 1 on at
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 426 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 358

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 353 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans