Receipt of Invoice adding lines using BOI with multiple POs

SOLVED

Hello,

I have two PO's and one line detail for each. I'm trying to add two lines to the Receipt of Invoice screen using BOI, using Sage 100 v2020 multiple POs. This is a new functionality with their cloud license. I get the header by setting Purchase Order for the two I want, after import it shows Multiple but my details come in only for one line. I noticed after running the script, I do have two rows in the Receipt Details table, but the second line has null for OrderLineKey and thus the invoiced qty and other details don't come through. Does anyone know what I"m missing here?

thanks

' First create ProvideX com object
Set oScript = CreateObject("ProvideX.Script")

'The Init method must be the first method called, and requires the path to the MAS90 home directory
oScript.Init("C:\Sage\Sage 100 Advanced\MAS90\Home")

'NewObject method creates a new MAS 90 Session object and returns the objects reference in oSS
Set oSS = oScript.NewObject("SY_Session")

If retVAL = 0 Then
User = "muUser"
Password = "password"
retVAL = oSS.nSetUser(User,Password)
End If

If retVAL = 0 Then
MsgBox(oSS.sLastErrorMsg)
oSS.nCleanup() ' Call Cleanup() before dropping the Session Object
oSS.DropObject()
Set oSS = Nothing
WScript.Quit
End If

Company = "EEC"
retVAL = oSS.nSetCompany(Company)

If retVAL = 0 Then
MsgBox(oSS.sLastErrorMsg)
oSS.nCleanup() ' Call Cleanup() before dropping the Session Object
oSS.DropObject()
Set oSS = Nothing
WScript.Quit
End If

' Get the Date to pass in with the MAS90 format
strDayOfMonth = Day(Date())
strMonth = Month(Date())
strYear = Year(Date())
YYYYMMDD = "20200528"

' Get the Module to pass in to set the Date
strModule = "P/O"

'The date format for the SetDate method must be YYYYMMDD
retVAL = oSS.nSetDate(strModule, YYYYMMDD)

retVal = oSS.nSetProgram(oSS.nLookupTask("PO_ReceiptOfInvoice_ui"))

Set oPOEntry = oScript.NewObject("PO_Receipt_bus",oSS)
Set oPOEntryLines = oPOEntry.oLines

retVal = oPOEntry.nSetValue("ReceiptType$", "I")
retVal = oPOEntry.nSetValue("APDivisionNo$", "01")

recNo = ""
retVal = oPOEntry.nGetNextNextInvoiceEntryNo(recNo)
retVal = oPOEntry.nSetKeyValue("ReceiptNo$", recNo)

retVal = oPOEntry.nSetKey()
If not(CBool(retVal)) Then MsgBox "SetKey Err: " & oPOEntry.sLastErrorMsg

retVal = oPOEntry.nSetValue("InvoiceDate$", "20200528")
retVal = oPOEntry.nSetValue("PurchaseOrderNo$", "0000184")
retVal = oPOEntry.nSetValue("PurchaseOrderNo$", "0000185")
retVal = oPOEntry.nSetValue("InvoiceNo$", "01YM12")
retVal = oPOEntry.nSetValue("MultiplePurchaseOrdersApplied$", "Y")

retVal = oPOEntryLines.nAddLine()
retVal = oPOEntryLines.nSetValue("ReceiptType$", "I")
retVal = oPOEntryLines.nSetValue("ItemCode$", "#12 INDOOR")
retVal = oPOEntryLines.nSetValue("LineKey$", "000001")
retVal = oPOEntryLines.nSetValue("OrderLineKey$", "000001")
retVal = oPOEntryLines.nSetValue("AppliedPurchaseOrderNo$", "0000184")
retVal = oPOEntryLines.nSetValue("UnitCost", .20)
retVal = oPOEntryLines.nSetValue("QuantityInvoiced", 4)
retVal = oPOEntryLines.nWrite()
If not(CBool(retVal)) Then MsgBox "Lines.Write Err: " & oPOEntryLines.sLastErrorMsg

retVal = oPOEntryLines.nAddLine()
retVal = oPOEntryLines.nSetValue("ReceiptType$", "I")
retVal = oPOEntryLines.nSetValue("ItemCode$", "#12 INDOOR")
retVal = oPOEntryLines.nSetValue("LineKey$", "000002")
retVal = oPOEntryLines.nSetValue("OrderLineKey$", "000001")
retVal = oPOEntryLines.nSetValue("AppliedPurchaseOrderNo$", "0000185")
retVal = oPOEntryLines.nSetValue("UnitCost", .20)
retVal = oPOEntryLines.nSetValue("QuantityInvoiced", 20)
retVal = oPOEntryLines.nWrite()
If not(CBool(retVal)) Then MsgBox "Lines.Write Err: " & oPOEntryLines.sLastErrorMsg

'write the header
retVal = oPOEntry.nWrite()
If not(CBool(retVal)) Then MsgBox "Header write Err: " & oPOEntry.sLastErrorMsg

MsgBox ("Done")

Parents
  • 0

    Try replacing this line:  retVal = oPOEntry.nSetValue("PurchaseOrderNo$", "0000185")

    With: retVal = oPOEntry.nApplyPurchaseOrderAdd("PurchaseOrderNo$", "0000185")

    The field MultiplePurchaseOrdersApplied$ is Read Only, it is set programmatically so you can remove this line:

    retVal = oPOEntry.nSetValue("MultiplePurchaseOrdersApplied$", "Y")

    In the code that is creating the detail you do not need the lines that set ReceiptType$ and LineKey$, that will be done by the AddLine()

     

  • 0 in reply to Steve Passmore

    Hi Steve, I get Error 548, in method APPLYPURCHASEORDERADD when replacing that line. The other information you provided helps alot. Thank you for those tid bits.

  • +1 in reply to youngmoon1982
    verified answer

    I believe ApplyPurchaseOrderAdd only accepts one argument, which is the PO #, not two, as is the case with SetValue. I think Steve copied your line and replaced only the method name while leaving the arguments by accident.

  • 0 in reply to David Speck

    Yes, absolutely. I'm sorry, I should of caught that. Doesn't error now, but still does not set to Y for that column and still second line not coming through.

    thanks

  • 0 in reply to youngmoon1982

    Look at Steve's answers above this sub section of replies. He explains the correct sequence to use for multiple POs across several answers.

  • 0 in reply to David Speck

    Oops, you are absolutely correct, a copy and paste and I didn't change the arguments in the method call.

  • 0 in reply to Steve Passmore

    Hi Steve,

    Modified the code but now get an error: Header write err: This receipt has no lines and has zero total amounts. I'm thinking something is not right with the parameters I'm passing the methods?

    Thank you so much

    retVal = oSS.nSetProgram(oSS.nLookupTask("PO_ReceiptOfInvoice_ui"))

    Set oPOEntry = oScript.NewObject("PO_Receipt_bus",oSS)
    Set oPOEntryLines = oPOEntry.oLines

    retVal = oPOEntry.nSetValue("ReceiptType$", "I")
    retVal = oPOEntry.nSetValue("APDivisionNo$", "01")

    recNo = ""
    retVal = oPOEntry.nGetNextNextInvoiceEntryNo(recNo)

    retVal = oPOEntry.nSetKeyValue("ReceiptNo$", recNo)

    retVal = oPOEntry.nSetKey()
    If not(CBool(retVal)) Then MsgBox "SetKey Err: " & oPOEntry.sLastErrorMsg

    retVal = oPOEntry.nSetValue("InvoiceDate$", "20200528")
    retVal = oPOEntry.nSetValue("InvoiceNo$", "01YM12")
    retVal = oPOEntry.nSetValue("PurchaseOrderNo$", "0000184")
    retVal = oPOEntry.nApplyPurchaseOrderUpdate("0000184","N","N","N")
    retVal = oPOEntry.nApplyPurchaseOrderAdd("0000185")
    retVal = oPOEntry.nApplyPurchaseOrderUpdate("0000185","N","N","N")
    retVal = oPOEntry.nApplyPurchaseOrderCopyLines(2)


    retVal = oPOEntryLines.nAddLine()
    retVal = oPOEntryLines.nSetValue("ItemCode$", "#12 INDOOR")
    retVal = oPOEntryLines.nSetValue("OrderLineKey$", "000001")
    retVal = oPOEntryLines.nSetValue("AppliedPurchaseOrderNo$", "0000184")
    retVal = oPOEntryLines.nSetValue("UnitCost", .20)
    retVal = oPOEntryLines.nSetValue("QuantityInvoiced", 4)
    retVal = oPOEntryLines.nWrite()
    If not(CBool(retVal)) Then MsgBox "Lines.Write Err: " & oPOEntryLines.sLastErrorMsg

    retVal = oPOEntryLines.nAddLine()
    retVal = oPOEntryLines.nSetValue("ItemCode$", "#12 INDOOR")
    retVal = oPOEntryLines.nSetValue("OrderLineKey$", "000001")
    retVal = oPOEntryLines.nSetValue("AppliedPurchaseOrderNo$", "0000185")
    retVal = oPOEntryLines.nSetValue("UnitCost", .20)
    retVal = oPOEntryLines.nSetValue("QuantityInvoiced", 20)
    retVal = oPOEntryLines.nWrite()
    If not(CBool(retVal)) Then MsgBox "Lines.Write Err: " & oPOEntryLines.sLastErrorMsg


    'write the header
    retVal = oPOEntry.nWrite()
    If not(CBool(retVal)) Then MsgBox "Header write Err: " & oPOEntry.sLastErrorMsg

    MsgBox ("Done")

Reply
  • 0 in reply to Steve Passmore

    Hi Steve,

    Modified the code but now get an error: Header write err: This receipt has no lines and has zero total amounts. I'm thinking something is not right with the parameters I'm passing the methods?

    Thank you so much

    retVal = oSS.nSetProgram(oSS.nLookupTask("PO_ReceiptOfInvoice_ui"))

    Set oPOEntry = oScript.NewObject("PO_Receipt_bus",oSS)
    Set oPOEntryLines = oPOEntry.oLines

    retVal = oPOEntry.nSetValue("ReceiptType$", "I")
    retVal = oPOEntry.nSetValue("APDivisionNo$", "01")

    recNo = ""
    retVal = oPOEntry.nGetNextNextInvoiceEntryNo(recNo)

    retVal = oPOEntry.nSetKeyValue("ReceiptNo$", recNo)

    retVal = oPOEntry.nSetKey()
    If not(CBool(retVal)) Then MsgBox "SetKey Err: " & oPOEntry.sLastErrorMsg

    retVal = oPOEntry.nSetValue("InvoiceDate$", "20200528")
    retVal = oPOEntry.nSetValue("InvoiceNo$", "01YM12")
    retVal = oPOEntry.nSetValue("PurchaseOrderNo$", "0000184")
    retVal = oPOEntry.nApplyPurchaseOrderUpdate("0000184","N","N","N")
    retVal = oPOEntry.nApplyPurchaseOrderAdd("0000185")
    retVal = oPOEntry.nApplyPurchaseOrderUpdate("0000185","N","N","N")
    retVal = oPOEntry.nApplyPurchaseOrderCopyLines(2)


    retVal = oPOEntryLines.nAddLine()
    retVal = oPOEntryLines.nSetValue("ItemCode$", "#12 INDOOR")
    retVal = oPOEntryLines.nSetValue("OrderLineKey$", "000001")
    retVal = oPOEntryLines.nSetValue("AppliedPurchaseOrderNo$", "0000184")
    retVal = oPOEntryLines.nSetValue("UnitCost", .20)
    retVal = oPOEntryLines.nSetValue("QuantityInvoiced", 4)
    retVal = oPOEntryLines.nWrite()
    If not(CBool(retVal)) Then MsgBox "Lines.Write Err: " & oPOEntryLines.sLastErrorMsg

    retVal = oPOEntryLines.nAddLine()
    retVal = oPOEntryLines.nSetValue("ItemCode$", "#12 INDOOR")
    retVal = oPOEntryLines.nSetValue("OrderLineKey$", "000001")
    retVal = oPOEntryLines.nSetValue("AppliedPurchaseOrderNo$", "0000185")
    retVal = oPOEntryLines.nSetValue("UnitCost", .20)
    retVal = oPOEntryLines.nSetValue("QuantityInvoiced", 20)
    retVal = oPOEntryLines.nWrite()
    If not(CBool(retVal)) Then MsgBox "Lines.Write Err: " & oPOEntryLines.sLastErrorMsg


    'write the header
    retVal = oPOEntry.nWrite()
    If not(CBool(retVal)) Then MsgBox "Header write Err: " & oPOEntry.sLastErrorMsg

    MsgBox ("Done")

Children
  • 0 in reply to youngmoon1982
    SUGGESTED

    I'll address some things that jump out to me in your code.

    The ApplyPurchaseOrderCopyLines() argument is a value returned to you, an integer value that is the number of lines copied successfully into the receipt.

    Unless you are referencing the specific lines that are copied, you would not need the ApplyPurchaseOrderCopyLines() method call.  In your situation you are copying the lines and then going on to add new lines using the AddLine() method.  This will result in duplicates.

    The lines are probably failing because there are fields that are not getting set.  Check the retVal on each SetValue() and if it fails (value is 0) check the LastErrorMsg$ property of the object for more information.  My guess is QuantityInvoiced is failing since there is no quantity ordered.

  • 0 in reply to Steve Passmore

    Yes, I found it was because I moved the invoice number up above the PO. Thank you, I'll play around and see what I can get. I really appreciate your help.

    thank you