Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to extend VendInvoiceDocumentDP class

(0) ShareShare
ReportReport
Posted on by 21
In VendInvoiceDocument report I have added additional four columns and use VendInvoiceDocumentDP class for extension.
 
I have extended the insertVendInvoiceDocumentTmp or populateVendInvoiceDocumentTmp, it works but the reference data of first line appear in second line and I couldn't figure it out why it happened. Means the sales price of M0005 is 600 and it shows with Item Number M0006.
 
 
Sample code
 
public void insertVendInvoiceDocumentTmp(NoYes _purchInvoiceTransOrTaxTrans, NoYes _vendPaymSched)
    {
        next insertVendInvoiceDocumentTmp(_purchInvoiceTransOrTaxTrans, _vendPaymSched);
        VendInvoiceDocumentTmp      vendInvoiceDocumentTmp = this.vendInvoiceDocumentTmp;
        real                        latestPurchasePrice;
        
        ItemId              _itemID;
        date                _invoiceDate;
        AccountNum          _accountNum;
        real                _purchPrice;
        DataAreaId          _areaId;
        _itemID = vendInvoiceDocumentTmp.ItemId;
        _invoiceDate = vendInvoiceDocumentTmp.InvoiceDate;
        _accountNum = vendInvoiceDocumentTmp.InvoiceNum;
        _purchPrice = vendInvoiceDocumentTmp.PurchPrice;
        _areaId = vendInvoiceDocumentTmp.DataAreaId;
        latestPurchasePrice = InventoryManager::getSpecificLatestPurchasePrice(_itemID, _invoiceDate);
        vendInvoiceDocumentTmp.BT_AccountNum = _accountNum;
        if(vendInvoiceDocumentTmp.PurchPrice != 0)
        {
            if(latestPurchasePrice != _purchPrice)
                VendInvoiceDocumentTmp.BT_DiffPercentage = ((_purchPrice - latestPurchasePrice) / _purchPrice) * 100;
            else
                VendInvoiceDocumentTmp.BT_DiffPercentage = 0;
        }
        vendInvoiceDocumentTmp.BT_DocumentDate = _invoiceDate;
        vendInvoiceDocumentTmp.BT_ItemOnHand = InventoryManager::getOnHand(_areaId, _itemID);
        vendInvoiceDocumentTmp.BT_LastPurchPrice = latestPurchasePrice;
        vendInvoiceDocumentTmp.BT_SalesPrice = InventTableModule::find(_itemID, ModuleInventPurchSales::Sales).Price;
    }
  • Martin Dráb Profile Picture
    234,665 Most Valuable Professional on at
    How to extend VendInvoiceDocumentDP class
    I can't solve your problem, because I don't know what you mean by "not worked". You'd have to give us more information.
     
    But I surely can give you a simple example:
    protected void populateVendInvoiceDocumentTmp(NoYes _purchInvoiceTransOrTaxTrans, NoYes _vendPaymSched)
    {
        next populateVendInvoiceDocumentTmp(_purchInvoiceTransOrTaxTrans, _vendPaymSched);
        
        vendInvoiceDocumentTmp.MyField = vendInvoiceJour.MyField;
    }
  • AA-22090818-0 Profile Picture
    21 on at
    How to extend VendInvoiceDocumentDP class
    Than what will be the best solution. Can I have sample because I have tried with either populate or insert both not worked.
  • Martin Dráb Profile Picture
    234,665 Most Valuable Professional on at
    How to extend VendInvoiceDocumentDP class
    There are several problems with insert(). For example, you can use only data that you have in fields of the temporary table, not all data you have in the provider class. You also make your code less discoverable but putting it at a different place than all the other code for the same purpose.
  • Suggested answer
    AA-22090818-0 Profile Picture
    21 on at
    How to extend VendInvoiceDocumentDP class
    Dear All,
     
    I have extended the VendInvoiceDocumentTmp table method insert and it's working fine.
  • Suggested answer
    Martin Dráb Profile Picture
    234,665 Most Valuable Professional on at
    How to extend VendInvoiceDocumentDP class
    If you open insertVendInvoiceDocumentTmp(), you'll see that it does two things: calls populateVendInvoiceDocumentTmp() to prepare the data and insert() to save the record to database. Therefore you should extend populateVendInvoiceDocumentTmp() - it's intended for this purpose and it's indeed call before insert().
  • AA-22090818-0 Profile Picture
    21 on at
    How to extend VendInvoiceDocumentDP class
    @Martin Drab
    Thanks for our valuable input, can you please guide which specific method i need to extend.
  • Suggested answer
    Martin Dráb Profile Picture
    234,665 Most Valuable Professional on at
    How to extend VendInvoiceDocumentDP class
    It's because you extended a wrong method. You're changing the buffer after inserting, which means that your values will be used when the next record is inserted.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans