Reputation: 187
I have the following code:
protected void SOLine_UsrMargin_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var salesOrderEntry = (SOLine)e.Row;
if (salesOrderEntry == null)
return;
decimal? lastCost = GetLastCost(salesOrderEntry.InventoryID);
decimal margin = (decimal)cache.GetValue<SOLineExt.usrMargin (salesOrderEntry); <-- Line 47
.
.
.
}
This code works fine when the user is adding/editing a Sales Order. They are getting the following Exception after they have save the Sales Order, create a Shipment and go to confirm it:
Object reference not set to an instance of an object.
Stack Trace: at PX.Objects.SO.SOOrderEntry_Extension.SOLine_UsrMargin_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e) in g:\projects\xxx\Automatica\Projects\XXX\WebSite\App_RuntimeCode\SOOrderEntry.cs:line 47 at PX.Data.PXCache.OnFieldUpdated(String name, Object row, Object oldValue, Boolean externalCall) at PX.Data.PXCache`1.a(TNode A_0, TNode A_1, TNode A_2)
This is running on Acumatica Version 6.10.1122
Upvotes: 0
Views: 159
Reputation: 7706
If you want to get the value of your custom field it will be better for you to change your code to something like this
SOLineExt rowExt = PXCache<SOLine>.GetExtension<SOLineExt>(salesOrderEntry);
decimal margin=0;// or set any default value for margin for calculation if rowExt==null
if(rowExt!=null)
{
margin = rowExt.usrMargin;
}
Also I will suggest you to rename salesOrderEntry
which is the instance of current row to something like currentRow
, so that your code become more readable.
Upvotes: 0