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, ...
Answered

How to extend VendInvoiceDocumentDP class

(0) ShareShare
ReportReport
Posted on by 62
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;
    }
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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.
  • Ahmed Alam Profile Picture
    62 on at
    @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
    237,965 Most Valuable Professional on at
    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().
  • Suggested answer
    Ahmed Alam Profile Picture
    62 on at
    Dear All,
     
    I have extended the VendInvoiceDocumentTmp table method insert and it's working fine.
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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.
  • Ahmed Alam Profile Picture
    62 on at
    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
    237,965 Most Valuable Professional on at
    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;
    }

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 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 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