Page 1 of 1

warehouse transfer business logic object problem

PostPosted: Mon Jan 18, 2016 4:29 pm
by perry
Hi,
Jiwa 7.0.149

I'm trying to split warehouse transfer before activation, however, find some weird behavior between objects.

The function below illustrate the problem that I'm having (full plugin attached).
Code: Select all
Private Sub TransferActivateBefore(ByRef Cancel As Boolean)
      Dim recid As String
      recid = WHTrans.RecID
       
      msgbox("Existing Transfer No.: " & WHTrans.TransferNo) 'this returns correct No.
      NewWHTrans = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaWhouseTransfer.clsWarehouseTransfer)(Nothing)
      msgbox("Existing Transfer No. (after init new object): " & WHTrans.TransferNo) 'this return blank No., as it should return the existing transfer No.
      
      WHTrans.Read(recid)
      msgbox("New Transfer No. (after read): " & NewWHTrans.TransferNo) 'this returns transfer no. from existing transfer object, as it should return blank transfer No.
      
      Throw New JiwaApplication.Exceptions.PluginAbortException("abort testing")
    End Sub


Basically, I have 2 warehouse transfer objects (existing and new transfer). However, they are somehow reference to each other, so I have 2 instances of the same transfer.

Re: warehouse transfer business logic object problem  Topic is solved

PostPosted: Mon Jan 18, 2016 5:13 pm
by Mike.Sheen
perry wrote:however, find some weird behavior between objects.
...
they are somehow reference to each other, so I have 2 instances of the same transfer.


If you change your Setup method to this, It behaves as I think you intended:

Code: Select all
Public Sub Setup(ByVal JiwaBusinessLogic As JiwaApplication.IJiwaBusinessLogic, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaBusinessLogicPlugin.Setup      
   If WHTrans Is Nothing Then ' Prevent creating of the split transfer in our TransferActivateBefore creating another transfer and possible recursing infinitely
      WHTrans = TryCast(JiwaBusinessLogic, JiwaWhouseTransfer.clsWarehouseTransfer)
      
      If Not WHTrans Is Nothing Then
         AddHandler WHTrans.TransferActivateBefore, AddressOf TransferActivateBefore
      End If
   End If       
End Sub


Because we create an instance of the class BusinessLogicPlugin ONCE - at login time, and then we invoke the Setup method of that same instance whenever the BusinessLogicFactory is used to create a new instance of the business logic, your Setup method was being invoked by the 2nd Warehouse transfer you created in the TransferActivateBefore handler and overwriting the WHTrans variable with the 2nd instance.

Mike

EDIT: I should add that if the Warehouse Transfer event TransferActivateBefore included the sender (the instance of the Warehouse Transfer business logic), then you would not need to store an instance into your local WHTrans variable, and the problem would have been avoided altogether. I've added bug 12402 to do just that - but for now the above work-around should suffice.

Re: Custom field lookup to locate items on a specific sales

PostPosted: Tue Jan 19, 2016 1:30 pm
by perry
Hi Mike,

Thanks, that fixed my problem.