I am trying to populate a UDF with the Gross Margin by line.

SUGGESTED

I have created a script, and it does not seem to work. Do I put it under column validation, or some other mode. Here is the script.

Retval=0
rExtcost
rExtamount=0
rQtyship=0
rUnitcost=0
rLineGM=0

Set oLines = oBusObj.AsObject(oBusObj.Lines)

oLines.MoveFirst

do until oLines.EOF
retVal=oLines.GetValue("ExtensionAmt", rExtamount)
retVal=oLines.GetValue("QuantityShipped", rQtyship)
retVal=oLines.GetValue("UnitCost", rUnitcost)
rExtcost= rqtyship * rUnitcost
rLineGM= ((rExtamount - rExtcost)/rExtamount)*100
retVal = oBusObj.SetValue("UDF_LINE_GM", rLineGM)
retVal=oLines.MoveNext()
loop

Parents
  • 0

    Is this in a sales order or invoice? Note that in a sales order the unit cost field is not populated.

  • 0 in reply to BigLouie

    It is Sales Order. My line does have a cost because it is standard cost.  The cost is populated on all of our orders, as right now we have a Sales Order that uses the work file to do this formula.  I assure you the cost is populated, and available.  We are not modified at all.

  • 0 in reply to Dean Yeater

    P.S. it is a field in SO_Detail.

  • 0 in reply to Dean Yeater

    I updated my script, and getting an error 88 at rExtcost

    Retval=0

    rExtcost

    rExtamount=0

    rQtyorder=0

    rUnitcost=0

    rLineGM=0

    Set oLines = oBusObj.AsObject(oBusObj.Lines)

    oLines.MoveFirst

    do until oLines.EOF

    retVal=oLines.GetValue("ExtensionAmt", rExtamount)

    retVal=oLines.GetValue("QuantityOrdered", rQtyorder)

    retVal=oLines.GetValue("UnitCost", rUnitcost)

    rExtcost= rqtyorder * rUnitcost

    rLineGM= (rExtamount - rExtcost)/rExtamount

    retVal = oBusObj.SetValue("UDF_LINE_GM", rLineGM)

    retVal=oLines.MoveNext()

    loop

  • 0 in reply to Dean Yeater

    You don't need to use a loop or oLines.  You should put the script on the SO_SalesOrderDetail table, on column post-validate of item and quantity.  When you attach it to this table, oBusObj is the line, so you don't need a loop at all.  Take out all of the oLines references and it should work.

  • 0 in reply to hyanaga

    Thanks Hyanaga

    I still get an error 88

    Error #88: Invalid/unknown property name

    Program    SY_Maint.pvc

    Line       3031

    Current script

    Retval=0

    rExtcost

    rExtamount=0

    rQtyorder=0

    rUnitcost=0

    rLineGM=0

    retVal=oLines.GetValue("ExtensionAmt", rExtamount)

    retVal=oLines.GetValue("QuantityOrdered", rQtyorder)

    retVal=oLines.GetValue("UnitCost", rUnitcost)

    rExtcost= rqtyorder * rUnitcost

    rLineGM= (rExtamount - rExtcost)/rExtamount

    retVal = oBusObj.SetValue("UDF_LINE_GM", rLineGM)

    retVal=oLines.MoveNext()

  • 0 in reply to Dean Yeater
    SUGGESTED

    Would be helpful if you can tell us which line in the script is throwing the error.

    I typically put msgbox() functions to display pop ups and you can tell where you are when the error occurs.

    However, my guess is that if this script is attached to a field in the SO_SalesOrderDetail file,   all of the references to oLines  should be ObusObj.

    oLines would only be used if the script was attached to SO_SalesOrderHeader and you then needed to access the detail lines associated with the header record.

  • 0 in reply to TomTarget

    You didn't remove all the oLines references.  You need to use oBusObj instead, which is the object for the line itself.  also remove the MoveNext.

    Retval=0

    rExtcost

    rExtamount=0

    rQtyorder=0

    rUnitcost=0

    rLineGM=0

    retVal=oBusObj.GetValue("ExtensionAmt", rExtamount)

    retVal=oBusObj.GetValue("QuantityOrdered", rQtyorder)

    retVal=oBusObj.GetValue("UnitCost", rUnitcost)

    rExtcost= rqtyorder * rUnitcost

    rLineGM= (rExtamount - rExtcost)/rExtamount

    retVal = oBusObj.SetValue("UDF_LINE_GM", rLineGM)

Reply
  • 0 in reply to TomTarget

    You didn't remove all the oLines references.  You need to use oBusObj instead, which is the object for the line itself.  also remove the MoveNext.

    Retval=0

    rExtcost

    rExtamount=0

    rQtyorder=0

    rUnitcost=0

    rLineGM=0

    retVal=oBusObj.GetValue("ExtensionAmt", rExtamount)

    retVal=oBusObj.GetValue("QuantityOrdered", rQtyorder)

    retVal=oBusObj.GetValue("UnitCost", rUnitcost)

    rExtcost= rqtyorder * rUnitcost

    rLineGM= (rExtamount - rExtcost)/rExtamount

    retVal = oBusObj.SetValue("UDF_LINE_GM", rLineGM)

Children