You're getting the error because you're declaring an Inventory business logic and not actually initialising it before trying to invoke the Read method. When .Read is called InventoryObject is actually nothing - which explains your error.
Change:
- Code: Select all
Dim InventoryObject As JiwaFinancials.Jiwa.JiwaInventory.Inventory
InventoryObject.Read(item.InventoryID)
To:
- Code: Select all
Dim InventoryObject As JiwaFinancials.Jiwa.JiwaInventory.Inventory = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaInventory.Inventory)(Nothing)
InventoryObject.Read(item.InventoryID)
Note that I've used a factory to create it, but you could have simply done
- Code: Select all
Dim InventoryObject As New JiwaFinancials.Jiwa.JiwaInventory.Inventory
I do recommend the factory method, however.
And yes - I think this is a little over-complicated for what you're trying to do - I replaced your KitBO_LineChanged with the following, and it was then correctly setting the component backorder values - no need to read the entire inventory item in for the kit header:
- Code: Select all
Sub KitBO_LineChanged (item As JiwaSales.SalesOrder.SalesOrderLine, CustFieldValue As JiwaApplication.CustomFields.CustomFieldValue)
Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(item.SalesOrderLines.SalesOrder.Client, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
If item.KitLineType = JiwaSales.SalesOrder.SalesOrder.SalesOrderKitLineTypes.e_SalesOrderKitHeader Then
If Integer.Parse(item.CustomFieldValues.ItemFromSettingName("KitBO").Contents) > 0 Then
For Each kitComponent As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine In item.SalesOrderLines
If kitComponent.KitHeader IsNot Nothing AndAlso kitComponent.KitHeader.Equals(item) Then
kitComponent.QuantityBackOrdered = (kitComponent.KitUnits * Integer.Parse(item.CustomFieldValues.ItemFromSettingName("KitBO").Contents))
End If
Next
End If
End If
End Sub