Hi Forum,
I am getting an <Error: 0 in Method WRITE> message when trying to update a component in Bill Detail table.
I've tried setting key values, SetKey(), Setkey(bmComponentkey)... with no luck.
Any suggestions?... here is the script
scrapPercentage = 0.000 : strItemCode = "" : oLines = 0 : bmItemCode = "": strBillNo = "": strBillRev = "": LineBillNo = "": LineRev = "": strLinesKey = ""
kBillNo = "" : kRevision = "" : kLineKey = "": kLineKeySeqNo = "": TotStdCost = 0: StdCost = 0: need = 0 : Rev = "" : bmItemCode = "" : LineBillNo = "" : LineKey = "" : CompRevision = "" : bmComponentKey = ""
'--------------------------------------------------------------------------
Dim oscript, oss, retval, soPrint
Set oscript = CreateObject("ProvideX.Script")
oscript.Init ("\\SAGE\Acctg\Version 2016\Sage 100 Advanced\MAS90\Home\")
Set oss = oscript.NewObject("SY_SESSION")
retval = oss.nSetUser("k4s", "k4SyStem")
retval = oss.nSetCompany("TST")
retval = oss.nSetModule("B/M")
retval = oss.nSetDate("B/M", "20180516")
'----------------------------------------------------------------------------
'sCompany = oSession.CompanyCode
'if sCompany = "FSC" then
'sComponent = "140-000007" : nPercent = 1.00
'-----------------------------------------------------------------------------
'Set excel object
Dim objExcel
Dim objWkbk
Set objExcel = CreateObject("Excel.Application")
Set objWkbk=objExcel.Workbooks.Open("C:\Apps\components\SCRAP.csv")
RowCount = objExcel.ActiveWorkbook.Sheets(1).UsedRange.Rows.count
MsgBox "Number of rows used in the excel sheet " & RowCount
'retMsg = oScript.AsObject(oScript.UI).MessageBox("",sMsg)
'-----------------------------------------------------------------------------
'Set Sage 100 objects
retVal = oss.nSetProgram(oss.nLookupTask("BM_Bill_ui"))
Set oBomItem = oScript.NewObject("BM_Bill_bus", oSS)
Set oLines = oScript.NewObject("BM_BillDetail_bus", oSS)
'-----------------------------------------------------------------------------
'Read Excel file (csv) with components to update and Process Sage 100 items
nextCustomerLine = "" : tmpItem = "" : tmpScrap = ""
'Do Until objExcel.cells(InitRow,1).Value = ""
for InitRow = 2 to RowCount
if objExcel.cells(InitRow,1).Value = "" then objExcel.Quit
tmpItem = objExcel.cells(InitRow,2).Value
tmpScrap = objExcel.cells(InitRow,5).Value
MsgBox "Item and Scrap: " & tmpItem & " " & tmpScrap
'retMsg = oSession.AsObject(oSession.UI).MessageBox("",sMsg)
sComponent = tmpItem
retVal = oLines.nSetBrowseIndex("kWHEREUSED", "kWHEREUSED")
'retVal = oLines.nSetKeyValue("ComponentItemCode$",sComponent)
retVal = oLines.nSetKey(sComponent)
retVal = oLines.nFind(sComponent)
retVal = oLines.nSetBrowseFilter(sComponent)
oLines.nMoveNext()
Do While Not oLines.nEOF
retVal = oLines.nGetValue("BillNo$", LineBillNo)
retVal = oLines.nGetValue("LineKey$", LineKey)
retVal = oLines.nGetValue("Revision$", Rev)
retVal = oLines.nGetValue("ComponentItemCode$", bmItemCode)
retVal = oLines.nGetValue("ComponentRevision$", CompRevision)
bmComponentKey = bmItemCode&LineBillNo&Rev&CompRevision&LineKey
'retVal = oLines.nSetKey(bmComponentKey)
MsgBox "sComponent: " & sComponent & " bmItemCode: " & bmItemCode & LineBillNo & " " & Rev & " " & CompRevision & " " & LineKey
'retMsg = oSession.AsObject(oSession.UI).MessageBox("",sMsg)
If sComponent <> bmItemCode then
exit do
else
'Set Key Values to write back current record
'retVal = oLines.nSetKeyValue("ComponentItemCode$", bmItemCode)
'retVal = oLines.nSetKeyValue("BillNo$", LineBillNo)
'retVal = oLines.nSetKeyValue("Revision$", Rev)
'retVal = oLines.nSetKeyValue("ComponentRevision$", CompRevision)
'retVal = oLines.nSetKeyValue("LineKey$", LineKey)
retVal = oLines.nSetKey(bmComponentKey)
retVal = oLines.nSetValue("ScrapPercent", nPercent)
retVal = oLines.nWrite()
'MsgBox "Write retVal = " & retVal & " nPercent value: " & nPercent
'MsgBox "Component: " & sComponent & ", % value: " & nPercent
End If
oLines.nMoveNext()
msgbox "next record"
Loop
MsgBox "Finished Processing LineBillNo Value: " & LineBillNo & " - " & LineRev & " Component: " & bmItemCode
'retVal = oSession.AsObject(oSession.UI).MessageBox("",sMsg)
Next