editing or adding to sales order snaphot custom field  Topic is solved

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

editing or adding to sales order snaphot custom field

Postby indikad » Fri Jan 20, 2017 9:58 am

Version 7.0.157

appreciate if someone can show me how to edit or add a new value to a custom field on the Sales Order - snapshot tab
( SO_HistoryCustomSettingValues )
was trying to execute this code off a custom button on the band on sales order , however get an error

"Object reference not set to an instance of an object "

( note - if I substitute CustomFieldValues ins place of CustomSettingValues - it wont even compile )

Code: Select all
SalesOrderForm.SalesOrder.SalesOrderHistorys(SalesOrderForm.SalesOrder.SelectedHistoryNo).CustomSettingValues.ItemFromSettingName("mySettingName").Contents = "True"
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: editing or adding to sales order snaphot custom field

Postby Mike.Sheen » Fri Jan 20, 2017 10:20 am

Hi Indika,

I don't have a 7.00.157.00 environment right now I can test with, but I did test with 7.00.176.00 and had no issue.

Attached is the plugin I used for my test - can you try it on your 7.00.157.00 environment to see if the problem occurs.

Mike
Attachments
Plugin SO History Custom Field Test.xml
Test Plugin
(30.74 KiB) Downloaded 841 times
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: editing or adding to sales order snaphot custom field

Postby indikad » Fri Jan 20, 2017 12:16 pm

Thanks for the attention Mike.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: editing or adding to sales order snaphot custom field

Postby indikad » Tue Jan 24, 2017 1:31 pm

I have got it working using your code line - thanks Mike.
I have another issues elsewhere if you could give me a tip/s please.

I am updating an order using the file watcher / csv import code ( modified from Jiwa file watcher code ).
Question 1
The code works where I need to update the ThisDel field. however using the above method to update the custom field ( snapshot custom field ) , I get the same error - "Object reference not set to an instance of an object."
This is using the Jiwa plugin scheduler service - so I don't have the sales order on screen. code is below.
see towrds the end - the code line given below fails.
salesOrder.SalesOrderHistorys(shSelectedHistoryNo).CustomSettingValues.ItemFromSettingName("ediSOPickDate").Contents = Date.Today.ToString()

Quesion 2 -
also as a phase 2 - that I have not tried yet - I want to be able to update the desired snaphot only. How do I make sure the csv importer code updates the snaphot I require ?

THANks in advance.

Code: Select all
'calling from
ScheduledExecutionPlugin.OnServiceStart
'as below

CSVSalesOrderWatcher = New JiwaFileWatcher(Plugin,  CONST_STRING_FILE_WATCHER_ROOT_FOLDER ) ' "C:\Temp"             
      AddHandler CSVSalesOrderWatcher.FileImport, AddressOf CSVSalesOrderPickConfirmationImport_ICE
      CSVSalesOrderWatcher.ImportAllFilesInWatchFolder()


'the bit of code in the CSVSalesOrderPickConfirmationImport_ICE is

      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaSales.SalesOrder.SalesOrder)(Nothing)      
      Dim sInvNo As String = ""
      '--debug code            
      Dim oLogFileWriter As StreamWriter
      If (System.IO.File.Exists("C:\Temp\EDI\Infa\In\log.txt")) Then
         System.IO.File.Delete("C:\Temp\EDI\Infa\In\log.txt")
      End If
      If Not(System.IO.File.Exists("C:\Temp\EDI\Infa\In\log.txt")) Then               
         oLogFileWriter   = New StreamWriter("C:\Temp\EDI\Infa\In\log.txt",True )         
         oLogFileWriter.WriteLine ("New log started ")
         oLogFileWriter.Flush()
      End If      
      Try
         '--debug code
         oLogFileWriter.WriteLine("before csv parser file name to read is " &  FileName.ToString() )
         oLogFileWriter.Flush()
         Using csvParser As New FileIO.TextFieldParser(FileName)   
            '--debug code
            oLogFileWriter.WriteLine("just after using  csv parser " )
            oLogFileWriter.Flush()
            csvParser.TextFieldType = FileIO.FieldType.Delimited
            csvParser.Delimiters = New String() {","}
            csvParser.HasFieldsEnclosedInQuotes = False
               
            Dim csvFields As String()
            Dim previousOrderNo As String = Nothing
            Dim newKey As String = ""
            '--debug code
            oLogFileWriter.WriteLine("just before debtor and inveory" )
            oLogFileWriter.Flush()
            Dim debtor As JiwaApplication.Entities.Debtor.Debtor = New JiwaApplication.Entities.Debtor.Debtor
            Dim inventory As JiwaApplication.Entities.Inventory.Inventory = New JiwaApplication.Entities.Inventory.Inventory                        
            '--debug code
            oLogFileWriter.WriteLine("just after debtor and inv  " )
            oLogFileWriter.Flush()
            
            Dim bHeaderRead As Boolean  = False             
            Dim bOrderObtained As Boolean  = False
            Dim shSelectedHistoryNo As Short = 0
                              
            '--debug code
            oLogFileWriter.WriteLine("just before do while  " )
            oLogFileWriter.Flush()
            Do While Not csvParser.EndOfData
               If Not bHeaderRead Then
                  '--debug code
                  oLogFileWriter.WriteLine("after bHeaderRead" )
                  csvFields = csvParser.ReadFields
                  bHeaderRead = True
               End If
               '--debug code
               oLogFileWriter.WriteLine("before  csvParser.ReadFields" )
               oLogFileWriter.Flush()
               
               csvFields = csvParser.ReadFields                                 
               sInvNo  =  csvFields(0).ToString().Trim() '-- JiwaInvoiceNo
               '--debug code
               oLogFileWriter.WriteLine("before  history number get " )
               oLogFileWriter.Flush()
               shSelectedHistoryNo = CShort(csvFields(1).ToString().Trim()) '-- snaphot no
               '--debug code
               oLogFileWriter.WriteLine("history number is " +  shSelectedHistoryNo.ToString())
               oLogFileWriter.Flush()
               If Not (bOrderObtained) Then
                  '--debug code
                  oLogFileWriter.WriteLine(" before order read  ")
                  oLogFileWriter.Flush()
                  salesOrder.Read(getSalesOrderIdByInvNo (sInvNo))                
                  bOrderObtained = True
                  '--debug code
                  oLogFileWriter.WriteLine(" after order read  ")
                  oLogFileWriter.Flush()
                  salesOrder.HistoryCustomSettings.Read()
                  If (salesOrder.SalesOrderStatus = JiwaSales.SalesOrder.SalesOrder.SalesOrderStatuses.e_SalesOrderProcessed  Or salesOrder.SalesOrderStatus = JiwaSales.SalesOrder.SalesOrder.SalesOrderStatuses.e_SalesOrderClosed ) Then
                     CSVSalesOrderWatcher.LogToEventLog("Failed to update ICE sales order InvNo: " + sInvNo + " FileName: " + FileName  + vbNewLine + " Order may be closed or processed. " + csvFields(6).ToString().Trim()  , System.Diagnostics.EventLogEntryType.FailureAudit )
                     Throw New Exception ( "Editing an order that is closed or processed error. ")
                     Return
                  End If
               End If
               '----------------------------------------------------------------------------
                '--- note the Item index can be line number or line id
               'if supplying with line number with a variable make sure
               'its a int and not long
               '---------------------------------------------------------------------------
               Dim salesOrderLine As JiwaSales.SalesOrder.SalesOrderLine             
               Dim sLineId As String = csvFields(3).ToString().Trim()
               salesOrderLine = salesOrder.SalesOrderLines.Item(sLineId)               
               
               Dim qtyThisDel As Decimal  = 0
               If Not (Decimal.TryParse(csvFields(6).ToString().Trim() , qtyThisDel )) Then
                  '---place a Error message On windows log and raise error - exit out
                  CSVSalesOrderWatcher.LogToEventLog("Failed to update ICE sales order InvNo: " + sInvNo + " FileName: " + FileName  + vbNewLine + " Could Not parse quantity del value " + csvFields(6).ToString().Trim()  , System.Diagnostics.EventLogEntryType.FailureAudit)
                  Throw New Exception ( "Quantity to deliver parse error. ")
                  Return
               End If
               salesOrderLine.QuantityThisDelivery = qtyThisDel
            Loop            
         
            If salesOrder.SalesOrderLines.Count > 0 Then
               'salesOrder.CustomFieldValues.ItemFromSettingName("ediSOPickDate").Contents  = Date.Today.ToString()   
               
               '--debug code
               oLogFileWriter.WriteLine(" before set custom field value ")   
               oLogFileWriter.Flush()
'               Dim soH As JiwaSales.SalesOrder.SalesOrderHistory
'               soH.SalesOrderHistorys.Read()
               'salesOrder.HistoryCustomSettings.Read()         
               salesOrder.SalesOrderHistorys(shSelectedHistoryNo).CustomSettingValues.ItemFromSettingName("ediSOPickDate").Contents = Date.Today.ToString()   
               
               '--debug code
               oLogFileWriter.WriteLine(" after set custom field value ")   
               oLogFileWriter.Flush()
               
               salesOrder.Save()
               'CSVSalesOrderWatcher.LogToEventLog(String.Format("Updated Sales Order Invoice No. '{0}' from File '{1}'", sInvNo , FileName), System.Diagnostics.EventLogEntryType.SuccessAudit)            
               CSVSalesOrderWatcher.LogToEventLog("Updated ICE sales order InvNo: " + sInvNo + " FileName: " + FileName , System.Diagnostics.EventLogEntryType.SuccessAudit)               
            Else
               CSVSalesOrderWatcher.LogToEventLog("Cannot update ICE sales order. No Lines in file. InvNo: " + sInvNo + " FileName: " + FileName , System.Diagnostics.EventLogEntryType.FailureAudit)
            End If               
            
         End Using         
      Catch ex As Exception
         CSVSalesOrderWatcher.LogToEventLog("Error Occured updating ICE sales order InvNo: " + sInvNo + " FileName: " + FileName + vbNewLine +  ex.Message  , System.Diagnostics.EventLogEntryType.FailureAudit)      
      End Try
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: editing or adding to sales order snaphot custom field

Postby Mike.Sheen » Tue Jan 24, 2017 1:44 pm

indikad wrote:see towrds the end - the code line given below fails.
salesOrder.SalesOrderHistorys(shSelectedHistoryNo).CustomSettingValues.ItemFromSettingName("ediSOPickDate").Contents = Date.Today.ToString()


If that line's throwing an "Object reference not set to an instance of an object." exception then you just need to isolate which part is null/nothing.

Check first that salesOrder.SalesOrderHistorys(shSelectedHistoryNo) IsNot Nothing - if it is, then shSelectedHistoryNo is invalid. If it isn't, then check salesOrder.SalesOrderHistorys(shSelectedHistoryNo).CustomSettingValues.ItemFromSettingName("ediSOPickDate") IsNot nothing - if it is nothing, then there is no custom field named "ediSOPickDate".

Your issue has to be either with shSelectedHistoryNo or "ediSOPickDate" being invalid, assuming your sale

indikad wrote:I want to be able to update the desired snaphot only. How do I make sure the csv importer code updates the snaphot I require ?

Set the SelectedHistoryNo of the sales order object to be the snapshot you want to modify before you modify any other properties.
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: editing or adding to sales order snaphot custom field

Postby indikad » Tue Jan 24, 2017 2:54 pm

Thanks for the clues Mike. I've been checking the objects.
The value of the shSelectedHistoryNo is 1 ( it is a variable of type short ).
salesOrder.SalesOrderHistorys(shSelectedHistoryNo) is NOT nothing
salesOrder.SalesOrderHistorys(shSelectedHistoryNo).CustomSettingValues is NOT nothing

The custom field exists too (ediSOPickDate)

however
the line below fails ( the same object ref error ) - is the shSelectedHistoryNo the cause ? is it zero based ? am I correct in passing a type Short value ?
Code: Select all
If (salesOrder.SalesOrderHistorys(shSelectedHistoryNo).CustomSettingValues.ItemFromSettingName("ediSOPickDate")) Is Nothing Then
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: editing or adding to sales order snaphot custom field

Postby indikad » Wed Jan 25, 2017 11:21 am

Think Ive got it working - it was the second line below that was the culprit ( salesOrder.HistoryCustomSettings.Read() )
Ive got one test working after commenting that line. will do some more tests.
Code: Select all
salesOrder.Read(getSalesOrderIdByInvNo (sInvNo))                
'salesOrder.HistoryCustomSettings.Read()
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: editing or adding to sales order snaphot custom field

Postby indikad » Wed Jan 25, 2017 12:54 pm

spoke too soon.
since I did a process and created a 2nd snaphot the error is back , regardless of having the line
salesOrder.HistoryCustomSettings.Read()
I have run out of ideas to test.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: editing or adding to sales order snaphot custom field

Postby indikad » Wed Jan 25, 2017 3:43 pm

Mike,
after some testing the attached code is where I am stuck with now.
I can see the code working for a basic order ( single snapshot and unprocessed )
as soon as I process a snapshot and create another snapshot, I cannot update the 2nd snaphot with this file watcher code.
the same "object reference not set..." error occurs. that too when I make the first change to the order - in my case the qty this del.
( * looks like a bug ? )

The plugin code and also the csv files I used are attached.

any ideas is appreciated
Attachments
OrderFiel_Snap02.csv
(171 Bytes) Downloaded 629 times
OrderFiel_Snap01.csv
(171 Bytes) Downloaded 1033 times
CSVFileWatcherCode_Buggy.xml
(61.56 KiB) Downloaded 975 times
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: editing or adding to sales order snaphot custom field  Topic is solved

Postby Mike.Sheen » Fri Jan 27, 2017 12:21 pm

Both your files have the same InvoiceLineID, but different snapshot numbers.

When you do this:

Code: Select all
shSelectedHistoryNo = CShort(csvFields(1).ToString().Trim()) '-- snaphot no               


This causes the SalesOrderLines collection to be populated with the lines of that snapshot.

So, later on when you do this:

Code: Select all
Dim salesOrderLine As JiwaSales.SalesOrder.SalesOrderLine             
Dim sLineId As String = csvFields(3).ToString().Trim()
salesOrderLine = salesOrder.SalesOrderLines.Item(sLineId)               


It's going to get null from salesOrder.SalesOrderLines.Item(sLineId) because there is no line in that snapshot with that InvoiceLineID.
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

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests