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

Notifications

Announcements

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?
I have the same question (0)
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    26,687 Super User 2025 Season 2 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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 338 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans