Hi all,
I was searching around and was not able to find issue that would provide me a hint on the problem I'm currently facing and was hoping to request some help from the community.
I'm getting the error of.. A batch number is not set up
here's the premise
I'm trying to create an invoice for an open sales order.
Using next available invoice number
Confirmed using batch number that's open and exist.
Confirmed that item in the invoice match the one on the sales order.
below is the script in full (with some masked information)
Set oScript = CreateObject ("ProvideX.Script") oScript.Init("\\xxxx\MAS90\Home") Set oSS = oScript.NewObject("SY_SESSION") retVAL = oSS.nlogon() If retVAL = 0 Then retVAL = oSS.nSetUser("xx", "yyyy") End If If retVAL = 0 Then WScript.Echo("0|Login failed") oSS.nCleanup() oSS.DropObject() Set oSS = Nothing WScript.Quit End If retVal = oSS.nSetCompany("TST") If retVAL = 0 Then WScript.Echo("0|Failed to set company") oSS.nCleanup() oSS.DropObject() Set oSS = Nothing WScript.Quit End If retVal = oSS.nSetDate("S/O","20220224") ' Date retVal = oSS.nSetModule("S/O") retVal = oSS.nSetProgram(oSS.nLookupTask("SO_Invoice_Ui")) Set oSOInvoice = oScript.NewObject("SO_Invoice_Bus", oSS) retVal = oSOInvoice.nSetKeyValue("InvoiceNo$", "0446739") retVal = oSOInvoice.nSetKey() If Not retVal = 1 Then retVal = oSOInvoice.nSetValue("ARDivisionNo$", "99") retVal = oSOInvoice.nSetValue("SalesOrderNo$", "0337750") If retVAL = -2 Then oSS.nCleanup() oSS.DropObject() Set oSS = Nothing WScript.Echo("2|Failed Setting Sales Order Number: " + oSOInvoice.sLastErrorMsg) WScript.quit End If retVal = oSOInvoice.nSetValue("CustomerNo$", "0076278") retVal = oSOInvoice.nSetValue("OrderDate$", "20220217") retVal = oSOInvoice.nSetValue("OrderType$", "S") retVal = oSOInvoice.nSetValue("InvoiceType$", "IN") retVal = oSOInvoice.nSetValue("ShipVia$", "UPSG") retVal = oSOInvoice.nSetValue("FOB$", "") retVal = oSOInvoice.nSetValue("WarehouseCode$", "200") retVal = oSOInvoice.nSetValue("ConfirmTo$", "") retVal = oSOInvoice.nSetValue("Comment$", "test") retVal = oSOInvoice.nSetValue("TermsCode$", "30") retVal = oSOInvoice.nSetValue("InvoiceDate$", "20220224") retVal = oSOInvoice.nSelectBatch("00217") retVal = oSOInvoice.oLines.nAddLine() retVal = oSOInvoice.oLines.nSetValue("ItemCode$", "SB-xxx-0.5") retVal = oSOInvoice.oLines.nSetValue("ItemType$", "1") retVal = oSOInvoice.oLines.nSetValue("ItemCodeDesc$", "test item") retVal = oSOInvoice.oLines.nSetValue("SalesAcctKey$", "000001") retVal = oSOInvoice.oLines.nSetValue("Quantity", 1.00000) retVal = oSOInvoice.oLines.nSetValue("Price", 87.00000) retVal = oSOInvoice.oLines.nSetValue("Cost", 11.80000) retVal = oSOInvoice.oLines.nSetValue("WarehouseCode$", "200") retVal = oSOInvoice.oLines.nSetValue("UnitOfMeasure$", "") retVal = oSOInvoice.oLines.nSetValue("TaxClass$", "TX") retVal = oSOInvoice.oLines.nSetValue("DropShip$", "N") retVal = oSOInvoice.oLines.nSetValue("QuantityOrdered", 1.00000) retVal = oSOInvoice.oLines.nSetValue("QuantityShipped", 1.00000) retVal = oSOInvoice.oLines.nSetValue("UnitPrice", 87.00000) retVal = oSOInvoice.oLines.nSetValue("Discount$", "Y") retVal = oSOInvoice.oLines.nWrite() If retVal = 0 Then msgVal = oSOInvoice.sLastErrorMsg errCode = 0 errMsg = errMsg & "|Failed updating Invoice: &" + msgVal oSS.nCleanup() oSS.DropObject() Set oss = Nothing Set oScript = Nothing WScript.Echo(errCode & errMsg) WScript.Quit End If retVal = oSOInvoice.nWrite() If retVal = 0 Then msgVal = oSOInvoice.sLastErrorMsg errCode = 0 errMsg = errMsg & "|Failed Inserting Invoice: &" + msgVal oSS.nCleanup() oSS.DropObject() Set oss = Nothing Set oScript = Nothing WScript.Echo(errCode & errMsg) WScript.Quit End If WScript.Echo("1") WScript.Quit Else WScript.Echo("0|Error: Invoice already exists in Sage") WScript.Quit End If oSOInvoice.DropObject() oSS.nCleanup() oSS.DropObject() Set oSOInvoice = Nothing Set oSS = Nothing Set oScript = Nothing