Friday 19 April 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

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...