error on BinLocationCollection.Read  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

error on BinLocationCollection.Read

Postby perry » Wed Aug 03, 2016 11:24 pm

Hi,
I think even this maybe a bug but still is technical/programming related.

It took me all day to debug this, so I would like to share my pain :twisted:.

Details: (Jiwa: 7.0.157)
I get "Object reference not set to an instance of an object." on
Code: Select all
 _Inventory = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaInventory.Inventory)(Nothing)
_Inventory.Read(_InventoryID)


error as below:
Code: Select all
   at JiwaFinancials.Jiwa.JiwaInventory.BinLocationCollection.Read()
   at JiwaFinancials.Jiwa.JiwaInventory.Inventory.Read(String RecID)
   at Lonicera.Jiwa.Standard.EDI.BL.OrderLine..ctor(Int64 EDIOrderLineID, Int64 EDIOrderID, Int32 OrderLineNo, String OrderItemCode, String OrderItemCodeType, String OrderItemCode2, String OrderItemCodeType2, String OrderItemDescription, Decimal OrderQty, Decimal OrderPackSize, Decimal OrderPrice, Decimal OrderTaxRate, String JiwaPartNo, String JiwaBarCode, Decimal JiwaQtyAvailable, Decimal JiwaQtyAssigned, Decimal JiwaPrice, Decimal JiwaPriceOverwrite, String ManuallySelectedPartNo, Boolean DonotImportThisLine, Boolean LineUpdated, Int32 QuantityDecimalPlaces, String InventoryID, String _JiwaInvoiceID, String _JiwaInvoiceLineID, OrderLines Lines)
   at Lonicera.Jiwa.Standard.EDI.BL.OrderLines.Read()
   at Lonicera.Jiwa.Standard.EDI.BL.Order.Read(String RecID)


the problem:
Code: Select all
_SalesOrder = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaSales.SalesOrder.SalesOrder)(Nothing)

RaiseEvent ProcessStart(Me, _SalesOrder, New System.EventArgs())

With _SalesOrder
   .CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrder, Debtor.DebtorID, True,,,, WarehouseID)
   '.Warehouse.IN_LogicalID = WarehouseID 
   .OrderNo = Me.CustomerPONo
   .Reference = Me.EDIOrderReferenceNo
   .ExpectedDeliveryDate = Me.RequestedDeliveryDate
   .SalesOrderHistorys(1).Notes = Me.Comments
End With
'JiwaApplication.Manager.Instance.Database.CurrentLogicalWarehouseID
'JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.IN_LogicalID
           
For Each line As BL.OrderLine In _OrderLines

   If Not line.DonotImportThisLine Then
      With _SalesOrder.SalesOrderLines
         .AddInventoryItem(line.InventoryID, JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, NewKey)
         If line.JiwaQtyAssigned = 0 Then
            .Item(NewKey).QuantityOrdered = line.OrderQty
         Else
            .Item(NewKey).QuantityOrdered = line.JiwaQtyAssigned
         End If

         .Item(NewKey).DiscountedPrice = line.JiwaPriceOverwrite

         line.AssignMapping(_SalesOrder.RecID, NewKey)
      End With
   End If
Next
Me.OrderApproved = True

RaiseEvent ProcessEnding(Me, _SalesOrder, New System.EventArgs())
_SalesOrder.Save()

Me.Save()

RaiseEvent ProcessEnd(Me, _SalesOrder, New System.EventArgs())


I was using below to create order in a different warehouse.
Code: Select all
.Warehouse.IN_LogicalID = WarehouseID 

Code was done pre v7.0.8x, so I dont remember why I didnt set logicalID in .CreateNew()...

so, after the code above, below variables actually hold different value. i.e. one is the current logical warehouse ID, the other become warehouse that order resides in
Code: Select all
'JiwaApplication.Manager.Instance.Database.CurrentLogicalWarehouseID
'JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.IN_LogicalID


now you get the error if you do Inventory.Read(InventoryID) on any item. This also happens to other plugins triggered by above code(e.g. line added/updated etc etc).

Fix:
Code: Select all
SalesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrder, Debtor.DebtorID, True,,,, WarehouseID)


This is an unusual scenario but I think the error on BinLocationCollection.Read() may still be a bug.
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: error on BinLocationCollection.Read

Postby Mike.Sheen » Thu Aug 11, 2016 8:13 pm

Hi Perry,

So If I am to understand this correctly, your problem is that setting the warehouse by performing

Code: Select all
.Warehouse.IN_LogicalID = WarehouseID


where the WarehouseID is different to the current warehouse, you get the "Object reference not set to an instance of an object" exception when subsequently creating a new inventory business logic and reading:

Code: Select all
 _Inventory = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaInventory.Inventory)(Nothing)
_Inventory.Read(_InventoryID)


But to work around that you found that rather than doing this, passing the warehouseID as a parameter of the CreateNew for the sales order, i.e.:

Code: Select all
.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrder, Debtor.DebtorID, True,,,, WarehouseID)


Then the exception does not occur. Is that correct?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: error on BinLocationCollection.Read

Postby perry » Fri Aug 12, 2016 12:45 pm

Yes, 100%
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: error on BinLocationCollection.Read  Topic is solved

Postby Mike.Sheen » Sat Nov 12, 2016 12:04 pm

Hi Perry,

This is because the Warehouse of the Sales Order is actually a reference to the Current Logical Warehouse of the system. Setting the properties of that will cause problems when other objects need to reference the current warehouse (As Inventory does to read certain things) if the values are inconsistent - so by setting the SalesOrder.Warehouse.IN_LogicalID you've introduced inconsistency as that warehouse object sits inside a logical warehouse collection which sits inside a physical warehouse inside a physical warehouse collection.

We should really make those properties read-only so you can't introduce inconsistency, or at least have the sales order Warehouse property be a copy of the current logical warehouse when instantiated rather than a reference to it.

I've logged DEV-5657 to address this.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests