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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Settling invoice for customer transaction through code in d 365

(0) ShareShare
ReportReport
Posted on by 439

Hi All,

I have created a batch for the settlement and i  have created a method as a code 

 /// 
    /// Settle the marked customer transaction.
    /// 
    /// 
    /// A CustTable record.
    /// 
    /// 
    /// A CustTrans record.
    /// 
    /// 
    /// A CustTrans record.
    /// 
    /// 
    /// Returns true or false.
    /// 
    public boolean doSettlement(CustTable _custTable,CustTrans _invCustTrans, CustTrans _payCustTrans)
    {
        boolean                 ret = false;
        CustTransOpen           invCustTransOpen, payCustTransOpen;
        SpecTransManager        specTransManager;    
        SpecTrans               specTransExists, specTransDel;
        ;

        invCustTransOpen = CustTransOpen::findRefId(_invCustTrans.RecId);
        payCustTransOpen = CustTransOpen::findRefId(_payCustTrans.RecId);
        
        ttsbegin;

        // If record exists related to customer transactions in Spectrans table then deletes the record and insert again
        select count(RecId) from specTransExists
            where specTransExists.SpecCompany       == _custTable.DataAreaId
                && specTransExists.SpecTableId      == _custTable.TableId
                && specTransExists.SpecRecId        == _custTable.RecId;

        if (specTransExists.RecId != 0)
        {
            delete_from specTransDel
                where specTransDel.SpecCompany       == _custTable.DataAreaId
                    && specTransDel.SpecTableId      == _custTable.TableId
                    && specTransDel.SpecRecId        == _custTable.RecId;
        }

        //Mark for settlement
        SpecTransExecutionContext specTransExecutionContext = SpecTransExecutionContext::newFromSource(_custTable);
        specTransManager = SpecTransManager::construct(specTransExecutionContext.parmSpecContext());

        //invoices
        if (!specTransManager.exist(invCustTransOpen.DataAreaId, invCustTransOpen.TableId, invCustTransOpen.RecId))
        {
            specTransManager.insert(invCustTransOpen.DataAreaId, invCustTransOpen.TableId, invCustTransOpen.RecId, invCustTransOpen.remainAmountCashDisc(), _invCustTrans.CurrencyCode);
        }
          
        //Payment(s)
        if (!specTransManager.exist(payCustTransOpen.DataAreaId, payCustTransOpen.TableId, payCustTransOpen.RecId))
        {
            specTransManager.insert(payCustTransOpen.DataAreaId, payCustTransOpen.TableId, payCustTransOpen.RecId, payCustTransOpen.remainAmountCashDisc(), _payCustTrans.CurrencyCode);
        }
        ttscommit;

        //Settle
        ret = CustTrans::settleTransaction(
                specTransExecutionContext,
                CustTransSettleTransactionParameters::construct());

        //if full settled and no durther settlement required then updated as paid    
        this.updateDepositTableAsPaidIfFullySettled(_invCustTrans);

        return ret;
    }

it seems working fine as far as settling the amount but when I do the same from the  settlement -> settlement transaction extra line appears 

550446.png

rohit.png

Please let me know if I am doing any thing wrong or I need to change any thing in my code to make sure settlement transcation and my batch works same???

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Rohit,

    Looks like you are trying to settle open transactions.

    Could you please highlight the extra line you see when you do a settle transaction from the UI?

  • rohit1900 Profile Picture
    439 on at

    Yes I am trying to settle the open transaction  The extra lines has been given the screen shot and they are the type of settlement and that too only appears when I settle from the Customer transcation  form -> settlement ->settle transactions

  • rohit1900 Profile Picture
    439 on at

    The code is correct For settling the open transactions??

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Code looks correct. Since you are trying to able to settle the transactions as well, should be working fine. However, looking at the code in the form, have you tried something like this blog?

    Maybe you can replicate the extra line you get while doing it from the UI.

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…

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
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans