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")

  • 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 David Speck
    SUGGESTED

    Also know that the stars need to be aligned just right (i.e. lots of matching field pre-requisites) in order for you to be "allowed" to add a PO after the first PO is set.

    Do it manually with the exact PO's, through the UI, to ensure there is not a mismatching field causing problems.

  • 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

  • 0 in reply to Kevin M

    Hi Kevin,

    Yes, I'm entering manually and setting values based on successful entries with multiple Purch Orders in my script. Comparing the field values for the header and detail lines in the database.

    thank you for the help

Reply Children
  • 0 in reply to youngmoon1982

    If your script crashes in the middle, sometimes things get left behind.  Entries in this table can block transactions for a PO too: PO_ReceiptReturnMatRqByPO

  • 0 in reply to Kevin M

    I'm getting everything in now, but I can't seem to get the column in the receipt header for Multiple PO's to flip to Y, even with using that method. If I manually fill out the form it is Y. Also again, the second line for the second PO in the receipt detail comes with null for the OrderLineKey even though I am setting that to the correct value. Hope I make a break through today, will keep you posted if I find a solution.

  • +1 in reply to youngmoon1982
    verified answer

    That field is Read Only and unfortunately the only code that changes its value to "Y" is in the ApplyPurchaseOrderCopyLines() method. 

    This was an oversight not anticipating a situation such as yours where you are not using that method and then adding in the detail directly without copying the lines from the applied p/o's first.

    I will have this written up so that a fix can be done so that whenever there are detail lines that reference multiple p/o's the MultiplePurchaseOrdersApplied$ field is set properly.

    A workaround may be to do the ApplyPurchaseOrderCopyLines() and then go through the detail lines updating each one for the invoiced quantities and amount.  You wouldn't do the AddLine() you would use the browse methods to move through and address each line.  Do the SetValue() method calls to set the quantities and/or costs and then Write() the detail line before browsing to the next.

  • 0 in reply to Steve Passmore

    Hi Steve, thank you again for your reply. I will forward this to my manager and see how this impacts us, if it can't be done, that's ok I just need to be able to communicate that to my manager. This is actually the answer I was looking for. Sometimes you have to play with the rules, which in this case is BOI. I really appreciate your help today and your further efforts. I appreciate the work around. I'll play around a bit and see if this works and let you know. Have a great weekend.