Default PO Landed Cost

SUGGESTED

Hi Everyone,

 

I’m working on a script to default the landed cost in ROG entry and I’m not having any luck with setting the values. Please be aware that this is my first attempt at creating a script like this.  I have successfully created simple scripts within the same business object so I am still learning.   I am working in a Sage 100 Advanced 2014 environment.  The Sage 100 user login has full administrator rights to all modules.

 

Scope:

In PO ROG, once you select accept to accept the ROG I would like to write the Landed cost type and the dollar amount. UDF fields are created in the PO ROG lines and on the header that totals up the total Lanced cost.

 

Here is the script. When I run the script I get the following error:

C:\Sage\.....\MAS90\MAS_ABC\POABC\PO_LandedCostReceipt.m4t does not have the correct permissions.

 

Dim sReceiptType

Dim sReceiptNo

Dim nTotalLC

Dim sLCType

Dim oLCReceipt

 

sReceiptType = "G"

sReceiptNo = ""

nTotalLC = 0

sLCType = "VOLM"

 

retVal=oBusObj.GetValue("ReceiptType$",sReceiptType)

 

if sReceiptType="G" then

                retVal=oBusObj.GetValue("ReceiptNo$",sReceiptNo)

                retVal=oBusObj.GetValue("UDF_PO_Total_Landed_Cost",nTotalLC)

                           

end if

 

oLCReceipt=oSession.GetObject("PO_LandedCostReceipt_bus")

if oLCReceipt<>0 then

                Set oLCReceipt=oSession.AsObject(oLCReceipt)

end if

 

retVal=oLCReceipt.SetKey(sReceiptType & sReceiptNo & sLCType)

if retVal<>0 then

                                retVal=oLCReceipt.setValue("ReceiptType$",sReceiptType)

                                retVal=oLCReceipt.setValue("ReceiptNo$",sReceiptNo)

                                retVal=oLCReceipt.setValue("LandedCostType$",sLCType)

                                retVal=oLCReceipt.setValue("LAndedCostAmount",nTotalLC)

                                retVal=oLCReceipt.Write()

end if

 

 

If I modify the following in the script I receive a new error message:

 

Change the setKey to SetKeyValue in the line below I will get the following error message:

Error88 – Wrong number of arguments or invalid property assignment oLCReceipt.SetKeyValue

 

retVal=oLCReceipt.SetKey(sReceiptType & sReceiptNo & sLCType)

 

 

I am not sure if this can be done or not. If I can default the landed cost information then please review my script and advise the changes.  Thank you for your time.

  • 0 in reply to Natasha Chang
    SUGGESTED

    Thanks for the post, Natasha Chang , but not being in VB Script makes it a challenge to use. What language is that, anyway? ProvideX?

    Anyway, Sander what you did wrong is this line:

    BusObject = oScript.NewObject("PO_LandedCostReceipt_BUS", oSS)

    That's basically instantiating a new object that is not connected in any way to your current business object. It will not have the needed permissions. Instead, you should write something like:

    Set oLandedCost = oSession.AsObject(oBusObj.PO_LandedCostReceiptObj)

    For Each key in dictReceiptAmountsByCostType
    retVal = olandedCost.SetKeyValue("ReceiptType$", receiptType)
    retVal = olandedCost.SetKeyValue("ReceiptNo$", receiptNo)
    retVal = olandedCost.SetKeyValue("LandedCostType$", landedCostType)
    retVal = olandedCost.SetKey()
    retVal = olandedCost.SetValue("LandedCostAmt", amt)
    retVal = olandedCost.Write()

    The main difference is that here you're using the LandedCostReceipt object of your current business object, which in our case is a ReceiptOfGoods header object. This assumes your familiar with Sage 100 Server-side scripting / User Defined Scripts. Basically, if you define the script as a user defined script, or if you attach it to a button, but specify that the script should execute on the server, then oBusObj will be a reference to your current business object, with all the permissions of the user who clicked the button or executed the action that fired the user defined script.

    If you don't have a copy of the Sage Scripting reference, you can download one here: sagecity.na.sage.com/.../98736

    Hope that helps.

    Aaron

  • 0 in reply to FunkMonkey33
    Are you sure that your getobject actually succeeded? In your logic, you continue on to your setkeys whether it succeeds or not.

    oLCReceipt=oSession.GetObject("PO_LandedCostReceipt_bus")
    if oLCReceipt<>0 then
    Set oLCReceipt=oSession.AsObject(oLCReceipt)
    end if

    REGARDLESS OF WHETHER THE ABOVE SUCCEEDED YOU ARE CONTINUING AS IF YOU WERE?
    retVal=oLCReceipt.SetKey(sReceiptType & sReceiptNo & sLCType)
  • 0 in reply to TomTarget
    Looks like not all of my code pasted in. There's a next in there.

    Anyway, the code you provided is very similar to a very sound policy suggested in the scripting reference in the link above. And I recommend it.

    However, what I'm saying is that if you just try to get the object using oLCReceipt=oSession.GetObject("PO_LandedCostReceipt_bus"), it will fail. You'll get a 0 back.

    What I discovered through trial and error is that getting a reference to the PO_LandedCostReceiptObj instance that is already a member of your current Receipt of Goods header, will work. That's why I recommend using oBusObj go get the reference, as in this code snippet:

    Set oLandedCost = oSession.AsObject(oBusObj.PO_LandedCostReceiptObj)

    Hope this helps someone. I tested it, it worked for me.

    Aaron