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