Script possible with PO RoG Landed Cost panel / table?

SOLVED

I am trying to script some sort of data flow from the receipt into the Landed Cost panel / table, but nothing seems to work.  I want to calculate a value based on receipt lines (conditional percentage), and write that value as a Landed Cost... without the user having to type it in.

I can get a line script to fire in PO_LandedCostReceipt but without being able to reference the Receipt details (or pass a pre-calculated value into the script somehow) this is useless to me.

Set/GetStorageVar does not seem to work (using oSession or oScript).

I can't find a way to open the main receipt object from within the PO_LandedCostReceipt script (eg. oHeaderObj gives an error).  Opening a new receipt object won't give me access to newly created receipts (only what's been previously saved).

Panel post load script won't fire, and even if it did I'd have the same problem with not having a pre-calculated value to write (or access to the receipt to calculate the value then).

Any ideas?

  • +1
    verified answer

    Hey Kevin I took a quick look. Have NOT tested this but here a couple things that might help.

    1) If you do the OBJ trick we've talked about or look at Object Reference you can see Landed Cost Receipt object is child of PO_Receipt_bus header object, that is you can do this:

    Set oLCReceipt = oBusObj.AsObject(oBusObj.PO_LandedCostsReceiptObj)

    Hopefully that will let you pass data in this direction and see the result in the Landed Cost grid.

    2) When you want to SetStorageVar across a child object, you can't do the normal oScript.SetStorageVar(var,value)

    Knowing that oScript is based on ScriptObject property of the business object and both of them have that property, try to reference the LC Rcpt ScriptObject with something like this:

    Set oScript4LC = oSession.AsObject(oSession.AsObject(oBusObj.PO_LandedCostsReceiptObj).ScriptObject)

    Then: 
    If BlahBlahBlah Then nLCFreight = 50.00 'pretend
    retVal = oScript4LC.SetStorageVar("varLCType","FRGHT")
    retVal = oScript4LC.SetStorageVar("varFreightAmt",nLCFreight)

    Now in your LC script use the normal oScript to GetStorageVar
    sLCType = "" : nLCFrt = 0.00
    retVal = oScript.GetStorageVar("varLCType",sLCType)
    r=oScript.DebugPrint("sLCType = " & sLCType & " which should be FRGHT hopefully)
    retVal = oScript.GetStorageVar("varFreightAmt", nLCFrt)
    r=oScript.DebugPrint("nLCFrt = " & nLCFrt & " which should be 50 hopefully")

    But try Option 1 first to create / send data.

  • 0 in reply to Alnoor

    Thanks for the ideas Alnoor! 

    I'll test this when I get a chance, and report back with results.

  • 0 in reply to Kevin M

    Just fixed a typo in the Set oScript4LC line.

  • +1 in reply to Alnoor
    verified answer

    Thanks again Alnoor!

    Here is the magic... using method #1 in a button script.  Oddly there is no AddLine() for the LCR business object, but SetKey allowed me to insert / update a row all in one step (so the script ends up being more streamlined without having to detect if there is an existing row for the CostType I want to set).

    set oLCReceipt = oBusObj.AsObject(oBusObj.PO_LandedCostReceiptObj)
    ...
    sKeyPadded = sReceiptType & sReceiptNo & sCostType
    retVal = oLCReceipt.SetKey(sKeyPadded)
    ...

  • 0 in reply to Kevin M

    Woohoo! Way to go Kevin.