Skip to main content
Dynamics 365 Community / Forums / Finance forum / How to extend VendInvo...
Finance forum
Answered

How to extend VendInvoiceDocumentDP class

editSubscribe (0) ShareShare
ReportReport
Posted on by 13
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;
    }
Attachments
  • Martin Dráb Profile Picture
    Martin Dráb 222,646 Super User 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;
    }
  • Community member Profile Picture
    Community member 13 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
    Martin Dráb 222,646 Super User 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.
  • Verified answer
    Community member Profile Picture
    Community member 13 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
    Martin Dráb 222,646 Super User 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().
  • Community member Profile Picture
    Community member 13 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
    Martin Dráb 222,646 Super User 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.

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,126 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,646 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans