PO Receipt Detail Script to match QtyInv to QtyRec

SOLVED

I'm trying to get the QuantityInvoiced to change to whatever the QuantityReceived is for each line item on Receipt Of Invoice Entry. 

Probably a button script. I have plenty of scripts in place, but I've never written one to cycle through each line. Any tips on how to accomplish this?

  • 0

    Run from a header event or button script.

    Set oLines = oSession.AsObject(oBusObj.Lines)

    retVal = oLines.MoveFirst()

    do until oLines.EoF

    ' do stuff…

    retVal = oLines.MoveNext()

    loop ' oLines

  • 0 in reply to Kevin M

    Thank you. It doesn't seem to be triggering on any header events though. Might it have something to do with the 'Do you want to invoice the complete purchase order?" message box that comes up on the Lines tab?

    This is my script:

    if oSession.CompanyCode = "MBT" then

    nqtyrec = 0
    nqtyinv = 0
    oLines = 0

    retVal = oBusObj.GetValue("QuantityReceived",nqtyrec)
    retVal = oBusObj.GetValue("QuantityInvoiced",nqtyinv)

    Set oLines = oSession.AsObject(oBusObj.Lines)
    retVal = oLines.MoveFirst()

    do until oLines.EOF

    retVal = oLines.SetValue("QuantityInvoiced", nqtyrec)
    retVal = oLines.Write()
    retVal = oLines.MoveNext()

    loop

    end if

  • +1 in reply to Brown0987
    verified answer

    You're right that the "do you want to..." pop-up question bypasses line events, which is why you need to use a header event or button script.

    Go with the header table PreTotals, which always runs.  Your GetValue needs to be from oLines (not oBusObj), and done inside the loop.

  • 0 in reply to Kevin M

    Those prompts bypass detail field level events but the detail's pre-write event should always be triggered.  If you always want to enforce this, then the detail pre-write event should be the best event.  All you would need to do is get the value of QuantityReceived and set it in QuantityInvoiced, because you would be in the pre-write, you don't need to use SetKey or Write for the line.

  • 0 in reply to Kevin M

    What header table do I need to put this PreTotals on?  I need to do this exact same script.

    Thanks,

    Kevin

  • 0 in reply to Kevin Acorace

    If this is for PO receipts, then PO_ReceiptHeader.  However, you should filter the script to only header records that have a value in the headers invoice number field.

  • 0 in reply to David_Speck

    I'm trying to get the Invoice Qty to be the Receipt Qty just like this script above indicates with the changes suggested by Kevin M.  This is how I added it to the business object.  It doesn't seem to work.  Any Ideas?

    'Title: Set PO Inv Qty
    'Desc: Set Qty Inv = Qty Received
    'Bus Object: PO_ReceiptOfInvoiceDetail_bus
    'Event: Table Pre-Totals

    'Version 1.02

    'Created by KJA on 10/24/2022

    ' -------------------------SCRIPT START ------------------------------------

    'If oSession.CompanyCode = "ADX" OR oSession.CompanyCode = "ZIT" OR oSession.CompanyCode = "ZZF" then
    If oSession.CompanyCode = "ZZF" then
    retVAl = oScript.DebugPrint("GOT HERE Company Validated.")


    nqtyrec = 0
    nqtyinv = 0
    oLines = 0


    Set oLines = oSession.AsObject(oBusObj.Lines)

    retVal = oLines.MoveFirst()

    do until oLines.EOF

    retVal = oLines.GetValue("QuantityReceived",nqtyrec)
    retVal = oLines.GetValue("QuantityInvoiced",nqtyinv)

    retVal = oLines.SetValue("QuantityInvoiced", nqtyrec)
    retVal = oLines.Write()
    retVal = oLines.MoveNext()

    loop



    end if

  • 0 in reply to Kevin Acorace

    Add a filter to only run for ReceiptType = "I".

    Did you see your DebugPrint show successfully (to make sure the script is actually running...)?

  • 0 in reply to Kevin M

    Hello Kevin,

    Thanks for getting back to me.  It doesn't look like it is getting into the script at all, and I can't seem to figure out why.  This is all I get in the debug window. 

    Thanks,

    Kevin