Hi I just want to ask what is the problem in my code. When updating the Order entry it doens't update the real Order number, instead it update the next record.
I'm updating the following fields:
Below is my code:
I have suspected with this line:
See code in full.
I'm updating the following fields:
Code:
OEORD1headerFields.FieldByName("PONUMBER").Value = PONUMBER ' Purchase Order Number
OEORD1headerFields.FieldByName("SHIPTRACK").Value = SHIPTRACK ' Shipment Tracking Number
OEORD1headerFields.FieldByName("SHIPVIA").Value = SHIPVIA ' Ship-Via Code
OEORD1headerFields.FieldByName("REFERENCE").PutWithoutVerification(REFERENCE) ' Order Reference
Below is my code:
I have suspected with this line:
Code:
OEORD1headerFields.FieldByName("ORDNUMBER").PutWithoutVerification(ORDERNO)
See code in full.
Code:
Public Function fSAGEUpdateSO(ByVal sSystemConnection As String, ByRef ORDERNO As String, ByVal SHIPVIA As String, ByVal SHIPTRACK As String, ByVal PONUMBER As String, ByVal REFERENCE As String, ByRef sError As String) As Boolean
Try
'LINENUM = "-1"
' ================================
' DECLARE ENVIRONMENT
' ================================
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
mDBLinkCmpRW = sSageSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)
Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
mDBLinkSysRW = sSageSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_SYSTEM, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)
Dim temp As Boolean
Dim OEORD1header As AccpacCOMAPI.AccpacView
Dim OEORD1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0520", OEORD1header)
OEORD1headerFields = OEORD1header.Fields
Dim OEORD1detail1 As AccpacCOMAPI.AccpacView
Dim OEORD1detail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0500", OEORD1detail1)
OEORD1detail1Fields = OEORD1detail1.Fields
Dim OEORD1detail2 As AccpacCOMAPI.AccpacView
Dim OEORD1detail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0740", OEORD1detail2)
OEORD1detail2Fields = OEORD1detail2.Fields
Dim OEORD1detail3 As AccpacCOMAPI.AccpacView
Dim OEORD1detail3Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0180", OEORD1detail3)
OEORD1detail3Fields = OEORD1detail3.Fields
Dim OEORD1detail4 As AccpacCOMAPI.AccpacView
Dim OEORD1detail4Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0526", OEORD1detail4)
OEORD1detail4Fields = OEORD1detail4.Fields
Dim OEORD1detail5 As AccpacCOMAPI.AccpacView
Dim OEORD1detail5Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0522", OEORD1detail5)
OEORD1detail5Fields = OEORD1detail5.Fields
Dim OEORD1detail6 As AccpacCOMAPI.AccpacView
Dim OEORD1detail6Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0508", OEORD1detail6)
OEORD1detail6Fields = OEORD1detail6.Fields
Dim OEORD1detail7 As AccpacCOMAPI.AccpacView
Dim OEORD1detail7Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0507", OEORD1detail7)
OEORD1detail7Fields = OEORD1detail7.Fields
Dim OEORD1detail8 As AccpacCOMAPI.AccpacView
Dim OEORD1detail8Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0501", OEORD1detail8)
OEORD1detail8Fields = OEORD1detail8.Fields
Dim OEORD1detail9 As AccpacCOMAPI.AccpacView
Dim OEORD1detail9Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0502", OEORD1detail9)
OEORD1detail9Fields = OEORD1detail9.Fields
Dim OEORD1detail10 As AccpacCOMAPI.AccpacView
Dim OEORD1detail10Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0504", OEORD1detail10)
OEORD1detail10Fields = OEORD1detail10.Fields
Dim OEORD1detail11 As AccpacCOMAPI.AccpacView
Dim OEORD1detail11Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0506", OEORD1detail11)
OEORD1detail11Fields = OEORD1detail11.Fields
Dim OEORD1detail12 As AccpacCOMAPI.AccpacView
Dim OEORD1detail12Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0503", OEORD1detail12)
OEORD1detail12Fields = OEORD1detail12.Fields
OEORD1header.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail1, Nothing, OEORD1detail3, OEORD1detail2, OEORD1detail4, OEORD1detail5})
OEORD1detail1.Compose(New AccpacCOMAPI.AccpacView() {OEORD1header, OEORD1detail8, OEORD1detail12, OEORD1detail9, OEORD1detail6, OEORD1detail7})
OEORD1detail2.Compose(New AccpacCOMAPI.AccpacView() {OEORD1header})
OEORD1detail3.Compose(New AccpacCOMAPI.AccpacView() {OEORD1header, OEORD1detail1})
OEORD1detail4.Compose(New AccpacCOMAPI.AccpacView() {OEORD1header})
OEORD1detail5.Compose(New AccpacCOMAPI.AccpacView() {OEORD1header})
OEORD1detail6.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail1})
OEORD1detail7.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail1})
OEORD1detail8.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail1})
OEORD1detail9.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail1, OEORD1detail10, OEORD1detail11})
OEORD1detail10.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail9})
OEORD1detail11.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail9})
OEORD1detail12.Compose(New AccpacCOMAPI.AccpacView() {OEORD1detail1})
' ================================
' OPEN SALES ORDER
' ================================
OEORD1headerFields.FieldByName("DRIVENBYUI").Value = "1" ' Driven by UI
OEORD1detail1Fields.FieldByName("DRIVENBYUI").Value = "1" ' Driven by UI
OEORD1header.Cancel()
OEORD1header.Cancel()
OEORD1header.Init()
OEORD1detail2.Browse("", 1)
OEORD1detail2.Fetch()
temp = OEORD1header.Exists
OEORD1headerFields.FieldByName("ORDNUMBER").PutWithoutVerification(ORDERNO) ' Order Number
OEORD1header.Browse("", 0)
OEORD1header.Fetch()
OEORD1header.Order = 0
OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-32767") ' Line Number
OEORD1detail1.Browse("", 1)
OEORD1detail1.Fetch()
OEORD1detail9Fields.FieldByName("PRNCOMPNUM").PutWithoutVerification("-2147483647") ' Parent Component Number
OEORD1detail9Fields.FieldByName("COMPNUM").PutWithoutVerification("-2147483647") ' Component Number
OEORD1detail9.Browse("", 1)
OEORD1detail9.Fetch()
OEORD1detail3Fields.FieldByName("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail3.Browse("", 1)
OEORD1detail3.Fetch()
OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1detail2.Browse("", 1)
OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
temp = OEORD1header.Exists
OEORD1headerFields.FieldByName("PONUMBER").Value = PONUMBER ' Purchase Order Number
OEORD1headerFields.FieldByName("SHIPTRACK").Value = SHIPTRACK ' Shipment Tracking Number
OEORD1headerFields.FieldByName("SHIPVIA").Value = SHIPVIA ' Ship-Via Code
OEORD1headerFields.FieldByName("OECOMMAND").Value = "4" ' Process O/E Command
OEORD1headerFields.FieldByName("REFERENCE").PutWithoutVerification(REFERENCE) ' Order Reference
OEORD1header.Process()
OEORD1header.Order = 1
temp = OEORD1header.Exists
OEORD1header.Update()
OEORD1header.Read()
OEORD1header.Order = 0
OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-32767") ' Line Number
OEORD1detail1.Browse("", 1)
OEORD1detail1.Fetch()
OEORD1detail9Fields.FieldByName("PRNCOMPNUM").PutWithoutVerification("-2147483647") ' Parent Component Number
OEORD1detail9Fields.FieldByName("COMPNUM").PutWithoutVerification("-2147483647") ' Component Number
OEORD1detail9.Browse("", 1)
OEORD1detail9.Fetch()
OEORD1detail3Fields.FieldByName("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail3.Browse("", 1)
OEORD1detail3.Fetch()
OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1detail2.Browse("", 1)
OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
temp = OEORD1header.Exists
Return True
Catch ex As Exception
sError = Err.Description
fHandleSageErrors(sError)
sError = "ERR~~<Order - " & ORDERNO & "> " & sError
End Try
Return False
End Function