File Watcher creating a Shipment BookIn  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

File Watcher creating a Shipment BookIn

Postby DannyC » Tue Jan 18, 2022 5:43 pm

I'm creating a book-in from a CSV file using the File Watcher. version 7.2.1 SR8.

When I create the book-in based on the ShipmentID it pulls in all the lines from the shipment. No issues there except in my file, I may only have a small selection of the possible lines, so maybe the shipment has 50 lines, my bookin might only need to show 10.

Fortunately I'm provided the original ShipmentLineID in the file, so to populate the quantity I'm matching the ShipmentLineID and the file-provided ID so I can correctly set the bookin line quantity.
My problem is that the quantity is only getting set on the last line in my file. All the preceding lines are showing the quantity as 0.
I just can't work out where the syntax is wrong so I think another pair of eyes might spot it.

Here's my code - it's in VB because the standard File Watcher plugin is in VB.

Code: Select all
Private Sub CSVBookInImport(ByVal FileName As String)                  
   'SAMPLE CSV INPUT FILE
   '=======================================================================
   'ShipmentNo,PONumber,PartNo,QtyReceived,SubQty,SerialNo,ExpiryDate,LINEID
   'I01679S,PO0029064,DAYS-203B,20,20,,,A927C46898E347448837
   'I01679S,PO0029064,DAYS-203B,100,100,,,AA086DB2D75340FC80EC
   'I01679S,PO0029524,HLC-751-300005,16,16,,,7111DB3C0F76488E9605
   'I01679S,PO0028477,HLC-751-300005,11,11,,,FC7688847B6A4558934A
   'I01679S,PO0029064,HLC-751-300005,1,1,,,0B7BBAE15BE94E82A776
   'I01679S,PO0028477,SHH-521APL002,22,22,,,BDAF0B2108DA4533B4C8
   'I01679S,PO0029524,SHH-521APL002,24,24,,,0ACEB78D74C14421AEBD
   'I01679S,PO0029524,SHH-845PL001,14,14,,,7B70EA33EADE48118E61
   '=======================================================================
   SyncLock JiwaFinancials.Jiwa.JiwaApplication.Manager.CriticalSectionFlag
      Dim bookIn As JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.BookIn = _plugin.Manager.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.BookIn)(Nothing)         
                  
      Using csvParser As New FileIO.TextFieldParser(FileName)            
         csvParser.TextFieldType = FileIO.FieldType.Delimited
         csvParser.Delimiters = New String() {","}
         csvParser.HasFieldsEnclosedInQuotes = False
               
         Dim csvFields As String()
         Dim previousOrderNo As String = Nothing   
            
         csvFields = csvParser.ReadFields  'Move past the first row
         Do While Not csvParser.EndOfData
            csvFields = csvParser.ReadFields
                                    
            If Not previousOrderNo Is Nothing AndAlso csvFields(0) <> previousOrderNo Then
               ' The shipment No. has changed - save the current bookin
               bookIn.Save()
               CSVBookinWatcher.LogToEventLog(String.Format("Imported book-in for shipment. '{0}' ", csvFields(0)), System.Diagnostics.EventLogEntryType.SuccessAudit)
            End If
                  
      
            ' Create a new book-in
            'Find the shipment ID
            bookIn.CreateNew(GetShipmentID(csvFields(0), bookIn.Manager))

         
            For Each mybookInLine As JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.Line In bookIn.Lines
               CSVBookinWatcher.LogToEventLog(String.Format("ShipmentLineID '{0}'.  FileID '{1}' ",mybookInLine.ShipmentLine.RecID,  csvFields(7)), System.Diagnostics.EventLogEntryType.SuccessAudit)
               If mybookInLine.ShipmentLine.RecID = csvFields(7) Then
                  mybookInLine.Quantity = csvFields(3)
               End If
            Next
            
         Loop            
               
         If  bookIn.Lines.Count > 0 Then
            For Each mybookInLine As JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.Line In bookIn.Lines
               If mybookInLine.Quantity = 0 Then
                  ' mybookInLine.Lines.Remove(mybookInLine)
                  '  This works but just remming so I can see whats going on.
               End If
            Next               
            bookIn.Save()
            CSVBookinWatcher.LogToEventLog(String.Format("Imported Book-in  '{0}'.  Book In no. '{1}' ", csvFields(0), bookIn.BookInNo), System.Diagnostics.EventLogEntryType.SuccessAudit)            
         End If               
            
      End Using         
   End SyncLock
End Sub


The specific code block which sets the quantity is the bit that reads
Code: Select all
If mybookInLine.ShipmentLine.RecID = csvFields(7) Then
    mybookInLine.Quantity = csvFields(3)
End If
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: File Watcher creating a Shipment BookIn

Postby Mike.Sheen » Tue Jan 18, 2022 5:54 pm

You're on the right track by adding logging.

Would be useful to see the log entry which arises from:
Code: Select all
CSVBookinWatcher.LogToEventLog(String.Format("ShipmentLineID '{0}'.  FileID '{1}' ",mybookInLine.ShipmentLine.RecID,  csvFields(7)), System.Diagnostics.EventLogEntryType.SuccessAudit)
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: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: File Watcher creating a Shipment BookIn

Postby DannyC » Tue Jan 18, 2022 6:09 pm

Would be useful to see the log entry


Here's an example. Although there's a match the quantity either remains at 0, or gets reset back to 0.
Applog 1.png
Applog 1.png (10.41 KiB) Viewed 304 times


Note that there's several other log entries where there isn't a match - that's fairly obvious because for each file line, I am doing a For Each to iterate through all the lines to find a match. But then when there isn't a match it wouldn't be getting into the code block
Code: Select all
If mybookInLine.ShipmentLine.RecID = csvFields(7) Then
    mybookInLine.Quantity = csvFields(3)
End If
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: File Watcher creating a Shipment BookIn  Topic is solved

Postby Mike.Sheen » Tue Jan 18, 2022 6:14 pm

Ok, so in that specific example you've shown where the log shows they match - add a conditional breakpoint and trace through it - you'll find the answer quick enough.

right before this line:

Code: Select all
If mybookInLine.ShipmentLine.RecID = csvFields(7) Then


Add this:

Code: Select all
If csvFields(7) = "the value in the file" Then
    System.Diagnostics.Debugger.Launch()
End If


And then SURELY you'll be able to see the issue.
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: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: File Watcher creating a Shipment BookIn

Postby DannyC » Tue Jan 18, 2022 6:44 pm

Good idea.

And I found the culprit!
Code: Select all
bookIn.CreateNew(GetShipmentID(csvFields(0), bookIn.Manager))
.

It's firing on each line. I only need to create the BookIn on the first line, thereafter I can skip it.
So I just created a LineCounter and it only does the above code when the counter = 1.

Code: Select all
If LineCounter = 1 Then
   bookIn.CreateNew(GetShipmentID(csvFields(0), bookIn.Manager))
End If


Really appreciate the help. Like I said - another pair of eyes or another brain to drop a hint!
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 7 guests