Sales Order Creation - The xxx is invalid

Trying to get some pointers if anyone experienced the same issue or can provide some pointers in this matter.


One of our client upgraded to Sage 100 premium 2020 (from 2016) and our scripts we generated and were running okay in 2016 are getting The [sales order no] is invalid.

I tried attaching script here but it was flagged as spam, so I'm trying to see if there's a general info regarding what could be required in 2020 (that wasn't in 2016) or something that's no longer valid for sales order object?

  • Copy and paste the script text instead of trying to attach it.


  • Set oScript = CreateObject ("ProvideX.Script")
    oScript.Init("\\Sage\Sage 100 Premium\MAS90\Home")

    Set oSS = oScript.NewObject("SY_SESSION")

    retVAL = oSS.nlogon()

    If retVAL = 0 Then
    retVAL = oSS.nSetUser("xx", "xxxx")
    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("TS2")

    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","20210511") ' Date
    retVAL = oSS.nSetModule("S/O")

    retVAL = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_ui"))

    Set oSOOrder = oScript.NewObject("SO_SalesOrder_bus", oSS)

    retVAL = oSOOrder.nSetKeyValue("SalesOrderNo$", "E2178")
    retVAL = oSOOrder.nSetKey()

    If Not retVAL = 1 Then

    retVAL = oSOOrder.nSetValue("ARDivisionNo$", "00")
    retVAL = oSOOrder.nSetValue("CustomerNo$", "ECOMRCE")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Customer Number: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("OrderDate$", "20210511")

    retVAL = oSOOrder.nSetValue("OrderType$", "S")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Sales Order Number: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipVia$", "FEDX")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Shipping Method: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipWeight$", "5")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Shipping Weight: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("WarehouseCode$", "WEB")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Warehouse Code: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ConfirmTo$", "")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting ConfirmTo: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("CustomerPONo$", "")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Failed Inserting PoNum: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("Comment$", "")

    retVAL = oSOOrder.nSetValue("EmailAddress$", "[email protected]")

    retVAL = oSOOrder.nSetValue("TermsCode$", "")



    retVAL = oSOOrder.nSetValue("TaxSchedule$", "CA LA")

    retVAL = oSOOrder.nSetValue("DepositAmt", 142.00000)

    retVAL = oSOOrder.nSetValue("FreightAmt", 0.00000)

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Freight Amount: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If


    retVAL = oSOOrder.nSetValue("FOB$", "Destination")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting FOB: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipToName$", "Benjamin Symonds")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Ship To Name: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("UDF_SO_SHIPTONAME2$", "JCAS")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Ship To Name 2: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipToAddress1$", "808 S. Dubuque Street")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Ship To Address 1: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipToAddress2$", "")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Ship To Address 2: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipToCity$", "Iowa City")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Ship To City: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipToState$", "IA")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Ship To State: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipToZipCode$", "52240")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Ship To Zip Code: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("ShipToCountryCode$", "USA")


    retVAL = oSOOrder.nSetValue("BillToName$", "Benjamin Symonds")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To Name: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("UDF_SO_BILLTONAME2$", "JCAS")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To Name 2: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("BillToAddress1$", "808 S. Dubuque Street")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To Address 1: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("BillToAddress2$", "")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To Address 2: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("BillToAddress3$", "")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To Address 3: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("BillToCity$", "Iowa City")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To City: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("BillToState$", "IA")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To State: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("BillToZipCode$", "52240")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To Zip Code: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("BillToCountryCode$", "USA")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Bill To Country Code: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("UDF_WEB$", "Y")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting WEB: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Freight Account: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nSetValue("PaymentType$", "CHECK")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Payment Type: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nAddLine()

    If retVAL = 0 Then

    msgVal = oSOOrder.oLines.sLastErrorMsg
    msgVal2 = oSOOrder.sLastErrorMsg
    WScript.Echo(msgVal + msgVal2)

    End If


    retVAL = oSOOrder.oLines.nSetValue("ItemCode$", "80533")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting SKU: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("ItemType$", "1")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Description: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("WarehouseCode$", "WEB")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Warehouse Code on Item: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("UnitOfMeasure$", "EACH")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Unit Of Measure: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("TaxClass$", "NT")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Tax Class: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("DropShip$", "N")

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Drop Ship: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If


    retVAL = oSOOrder.oLines.nSetValue("QuantityOrdered", 2.00000)

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Quantity On Order: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("QuantityShipped", 0)

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Quantity Shipped: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("UnitPrice", 71.00000)

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Setting Unit Price: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.oLines.nSetValue("Discount$", "Y")

    retVAL = oSOOrder.oLines.nWrite()

    If retVAL = 0 Then

    msgVal = oSOOrder.oLines.sLastErrorMsg
    WScript.Echo(errMsg)

    End If

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error writing order entry lines." + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    retVAL = oSOOrder.nWrite()

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error writing order entry lines." + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    Set oSOSalesOrderTaxSummary = oScript.NewObject("SO_SalesOrderTaxSummary_bus", oSS)

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Submitting Sales Order Tax Summary: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    If retVAL = 0 Then
    oSOOrder.DropObject()
    oSOSalesOrderTaxSummary.DropObject()
    oSS.nCleanup()
    oSS.DropObject()
    Set oSOOrder = Nothing
    Set oSOSalesOrderTaxSummary = Nothing
    Set oSS = Nothing
    WScript.Echo("5")
    WScript.Quit
    Else
    WScript.Echo("1")
    End If
    Else
    msgTxt = oSOOrder.sLastErrorMsg
    WScript.Echo(msgTxt)
    End If

    oSOOrder.DropObject()
    oSOSalesOrderTaxSummary.DropObject()
    oSS.nCleanup()
    oSS.DropObject()

    Set oSOOrder = Nothing
    Set oSOSalesOrderTaxSummary = Nothing
    Set oSS = Nothing
    Set oScript = Nothing


  • Set oScript = CreateObject ("ProvideX.Script")
    oScript.Init("\\sscorsage20\Sage\Sage 100 Premium\MAS90\Home")

    Set oSS = oScript.NewObject("SY_SESSION")

    retVAL = oSS.nlogon()

    If retVAL = 0 Then
    retVAL = oSS.nSetUser("xx", "xxxx")
    End If

    retVAL = oSS.nSetCompany("TS2")


    retVAL = oSS.nSetDate("S/O","20210511") ' Date
    retVAL = oSS.nSetModule("S/O")

    retVAL = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_ui"))

    Set oSOOrder = oScript.NewObject("SO_SalesOrder_bus", oSS)

    retVAL = oSOOrder.nSetKeyValue("SalesOrderNo$", "E2178")
    retVAL = oSOOrder.nSetKey()


    retVAL = oSOOrder.nSetValue("ARDivisionNo$", "00")
    retVAL = oSOOrder.nSetValue("CustomerNo$", "ECOMRCE")
    retVAL = oSOOrder.nSetValue("OrderDate$", "20210511")
    retVAL = oSOOrder.nSetValue("OrderType$", "S")
    retVAL = oSOOrder.nSetValue("ShipVia$", "FEDX")
    retVAL = oSOOrder.nSetValue("ShipWeight$", "5")
    retVAL = oSOOrder.nSetValue("WarehouseCode$", "WEB")
    retVAL = oSOOrder.nSetValue("ConfirmTo$", "")
    retVAL = oSOOrder.nSetValue("CustomerPONo$", "")
    retVAL = oSOOrder.nSetValue("Comment$", "")
    retVAL = oSOOrder.nSetValue("EmailAddress$", "bxxxx")

    retVAL = oSOOrder.nSetValue("TermsCode$", "")
    retVAL = oSOOrder.nSetValue("TaxSchedule$", "CA LA")

    retVAL = oSOOrder.nSetValue("DepositAmt", 142.00000)
    retVAL = oSOOrder.nSetValue("FreightAmt", 0.00000)
    retVAL = oSOOrder.nSetValue("FOB$", "Destination")
    retVAL = oSOOrder.nSetValue("ShipToName$", "xxxx xxxx")


    retVAL = oSOOrder.nSetValue("UDF_SO_SHIPTONAME2$", "JCAS")

    retVAL = oSOOrder.nSetValue("ShipToAddress1$", "xxxx S. xxx Street")

    retVAL = oSOOrder.nSetValue("ShipToAddress2$", "")


    retVAL = oSOOrder.nSetValue("ShipToCity$", "Iowa City")


    retVAL = oSOOrder.nSetValue("ShipToState$", "IA")

    retVAL = oSOOrder.nSetValue("ShipToZipCode$", "xxxxx")


    retVAL = oSOOrder.nSetValue("ShipToCountryCode$", "USA")


    retVAL = oSOOrder.nSetValue("BillToName$", "xxx xxxx")


    retVAL = oSOOrder.nSetValue("UDF_SO_BILLTONAME2$", "JCAS")

    retVAL = oSOOrder.nSetValue("BillToAddress1$", "aa st")

    retVAL = oSOOrder.nSetValue("BillToAddress2$", "")


    retVAL = oSOOrder.nSetValue("BillToAddress3$", "")

    retVAL = oSOOrder.nSetValue("BillToCity$", "Iowa City")


    retVAL = oSOOrder.nSetValue("BillToState$", "IA")


    retVAL = oSOOrder.nSetValue("BillToZipCode$", "xxxxx")


    retVAL = oSOOrder.nSetValue("BillToCountryCode$", "USA")

    retVAL = oSOOrder.nSetValue("UDF_WEB$", "Y")

    retVAL = oSOOrder.nSetValue("PaymentType$", "CHECK")


    retVAL = oSOOrder.oLines.nAddLine()

    retVAL = oSOOrder.oLines.nSetValue("ItemCode$", "80533")

    retVAL = oSOOrder.oLines.nSetValue("ItemType$", "1")


    retVAL = oSOOrder.oLines.nSetValue("WarehouseCode$", "WEB")

    retVAL = oSOOrder.oLines.nSetValue("UnitOfMeasure$", "EACH")


    retVAL = oSOOrder.oLines.nSetValue("TaxClass$", "NT")


    retVAL = oSOOrder.oLines.nSetValue("DropShip$", "N")

    retVAL = oSOOrder.oLines.nSetValue("QuantityOrdered", 2.00000)

    retVAL = oSOOrder.oLines.nSetValue("QuantityShipped", 0)

    retVAL = oSOOrder.oLines.nSetValue("UnitPrice", 71.00000)


    retVAL = oSOOrder.oLines.nSetValue("Discount$", "Y")

    retVAL = oSOOrder.oLines.nWrite()

    retVAL = oSOOrder.nWrite()

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error writing order entry lines." + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    Set oSOSalesOrderTaxSummary = oScript.NewObject("SO_SalesOrderTaxSummary_bus", oSS)

    If retVAL = 0 Then

    msgVal = oSOOrder.sLastErrorMsg
    errCode = 0
    errMsg = errMsg & "|Error Submitting Sales Order Tax Summary: " + msgVal
    WScript.Echo(errCode & errMsg)

    oSS.nCleanup()
    oSS.DropObject()
    Set oss = Nothing
    Set oScript = Nothing

    WScript.Quit
    End If

    If retVAL = 0 Then
    oSOOrder.DropObject()
    oSOSalesOrderTaxSummary.DropObject()
    oSS.nCleanup()
    oSS.DropObject()
    Set oSOOrder = Nothing
    Set oSOSalesOrderTaxSummary = Nothing
    Set oSS = Nothing
    WScript.Echo("5")
    WScript.Quit
    Else
    WScript.Echo("1")
    End If
    Else
    msgTxt = oSOOrder.sLastErrorMsg
    WScript.Echo(msgTxt)
    End If

    oSOOrder.DropObject()
    oSOSalesOrderTaxSummary.DropObject()
    oSS.nCleanup()
    oSS.DropObject()

    Set oSOOrder = Nothing
    Set oSOSalesOrderTaxSummary = Nothing
    Set oSS = Nothing
    Set oScript = Nothing

  • in reply to Kevin M

    i think some of the information was sensitive, thank you though, made me look again!

  • in reply to TonyCah

    I skimmed through the code in the post above my reply and one issue is that you are treating the returned value from the SetKey method as a boolean but it can return -1 in the case of a warning, 0 in the case of a failure, 1 in the case of an existing record, and 2 in the case of a new record.  

    Also, an object's LastErrorMsg property can also contain "warnings", which are sometimes set for things like the sales order number if it isn't numeric but it is just a warning, which is why it is critical to understand a method's possible returned values and not expect everything to be a boolean.  

    So when you are outputting the LastErrorMsg, you should also output the returned value so you know what you are dealing with.

    You should refer to the online file layouts and object resource if you are ever unsure.  it typically does a good job of detailing what values can be returned by a method.

    Sage 100 File Layouts and Object Reference

  • in reply to David Speck

    Much appreciated and will go from there

  • in reply to David Speck

    I compared the file layout from my working version to the current, found a new field PayBalance.

    Tried to add that but same error of The E2178 is invalid. Thank you for your pointer though, I appreciate it

  • in reply to TonyCah

    If your SetKey is failing, then it doesn't matter what fields you attempt to set. 

    You need to determine which line is giving you those results, is it the Write?

    Also, what are you even doing with the SO_SalesOrderTaxSummary_bus?  You code near the end looks like it repeats itself and is rather confusing, you shouldn't have to bother with the SO_SalesOrderTaxSummary_bus object, just set your tax schedule, add your lines, and then call the SO_SalesOrder_Bus object's SalesTaxRecalculation method before the Write.

  • in reply to David Speck

    David,

    Thank you for the pointer again, completely missed that.

    It seems like setting the key is failing and it's returning 1.

    But attempting to create the number from UI allows me to do so and I checked all the usual suspect table (salesorder , detail, history, history detail)

    This is a bit weird to be honest as the client upgraded and every new order was returned with the invalid.

    I am now testing with upgraded sage (2020) but with database from a few months back. 
    I'm getting the same (invalid error) with new order

    but if I try to push older order number (confirmed does not exist in this test database), I'm getting missing record to calculate tax.

    Yea the whole bit with the SalesOrderTaxSummary has been commented out for now.

  • in reply to TonyCah

    I noticed you have the order number hardcoded, is there a good reason for this or it like that only for testing?

    When it was upgraded, did they change their SO history retention options, such as enabling it when it was previously not enabled?

    If SetKey is returning a 1, then that means it is an existing record, you may need to check SO_SalesOrderHeader to see if the order number exists in there.  Also check your company code and path that you are initializing the ProvideX.Script to.