Tuesday, 18 August 2015

Settle Vendor Invoice/Payment through X++ code - AX 2012

Hello Guys..!

Here I'm sharing code for Settle Vendor Invoice/Payment through X++ 

Code:
-----------
static void VendorSettlement(Args _args)
{
VendTable vendTable;
VendTrans invVendTrans, payVendTrans;
SpecTransManager manager;
CustVendTransData custVendTransData;
;
vendTable = VendTable::find("12345");
// Find the oldest unsettled invoice
select firstonly invVendTrans  order by TransDate asc
                            where invVendTrans.AccountNum == vendTable.AccountNum &&
                            invVendTrans.TransType == LedgerTransType::Purch &&
                            !invVendTrans.closed;
// Find the oldest unsettled payment
select firstonly payVendTrans order by TransDate asc
                    where payVendTrans.AccountNum == vendTable.AccountNum &&
                    payVendTrans.TransType == LedgerTransType::Payment &&
                    !payVendTrans.closed;
ttsbegin;
// Create an object of the CustVendTransData class with the invoice transaction as parameter
custVendTransData = CustVendTransData::construct(invVendTrans);
// Mark it for settlement
custVendTransData.markForSettlement(vendTable);
// Create an object of the CustVendTransData class with the payment transaction as parameter
custVendTransData = CustVendTransData::construct(payVendTrans);
//mark it for settlement
custVendTransData.markForSettlement(vendTable);
ttscommit;
// Settle all marked transactions
if(VendTrans::settleTransact(vendTable, null, true,SettleDatePrinc::DaysDate, systemdateget()))
info("Transactions settled");
}


@Rahul Talasila

6 comments:

  1. The code runs but does not do the update, probably u left out this step

    ReplyDelete
  2. I have same problem code runs but can't mark settlement. Can you share me the missing setps

    ReplyDelete
    Replies
    1. Hi Rahul,
      I have a scenario where I mark the vendor open transactions via x++ and update amount to settle column. Then I post PO invoice via x++. Then I need to settle partial payment (value given in update settlement amount)against the posted invoice. The method you posted completely settles payment against invoice, where as I want to settle partial payment. Plz share the sample code.
      Thanks
      Anamika

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Hi Anamika,

      Please refer the below links. I hope it solves your problem.

      http://www.andesoft.net/automatic-mark-settlement-transactions-payment-journal-ax-2012/
      http://xhellot.blogspot.com/2016/11/programmatically-settle-payment-journal.html
      https://hellodax.com/2015/06/22/auto-settle-from-custtransopen-when-create-journal-payment-lines-via-x/
      https://community.dynamics.com/ax/f/33/t/235739

      Delete

Sorting data in a form datasource in Dynamics Ax 2012 / D365F&O X++

In Microsoft Dynamics AX, you can sort a form datasource when the form is loaded. On the form, override the init method. After the call...