Friday, April 19, 2019

Object reference not set to an instance of an object Error while copying purchase order lines from another purchase order in Dynamics 365 F&O 8.0

I was getting the below error while trying to copy the purchase order lines from another order.And also specifically I'm getting this for inter-company purchase orders.


Object reference not set to an instance of an object Error.



Reason: 

 In my case there is an extension class for InterCompanySyncPurchLineType-> synchronizeInTradeCompany.
 and I was initializing next synchronizeInTradeCompany(); code after  AxSalesLine.

[ExtensionOf(classStr(InterCompanySyncPurchLineType))] final class SWInterCompanySyncPurchLineType_Extension { protected void synchronizeInTradeCompany() { AxSalesLine axSalesLineLocal = this.axSalesLine; next synchronizeInTradeCompany(); if (create || purchLine.fieldChanged(fieldNum(PurchLine, InventDimId))) { axSalesLineLocal.axInventDim().productDimensions(axInventDim); changecompany (purchLine.company()) { this.copyPurchaseBatchNumberToSalesTable(purchLine); } } } }


Solution: AxSalesLine doesn't get initialized until after the call to synchronizeInTradeCompany.
So, I swapped the code as shown below.

[ExtensionOf(classStr(InterCompanySyncPurchLineType))] final class SWInterCompanySyncPurchLineType_Extension { protected void synchronizeInTradeCompany() { next synchronizeInTradeCompany(); AxSalesLine axSalesLineLocal = this.axSalesLine; if (create || purchLine.fieldChanged(fieldNum(PurchLine, InventDimId))) { axSalesLineLocal.axInventDim().productDimensions(axInventDim); changecompany (purchLine.company()) { this.copyPurchaseBatchNumberToSalesTable(purchLine); } } } }


That's it. It worked fine.

@Rahul

No comments:

Post a Comment

Why do users often get confused about Dynamics 365 Customer Engagement (D365 CE), Dataverse, and the Power Platform?

  The Microsoft ecosystem for business applications can sometimes be difficult to navigate, especially when discussing Dynamics 365 Customer...