Hi all -
I have a script that runs on invoice detail lines. It is a button script the user can click if the invoice meets certain user-determined criteria. The button script loops through all the detail lines and checks the warehouse code assigned to each line. Once I have the warehouse value for the line, then I want to look at the WarehouseCode table and get a value of a UDF that is assigned on each warehouse code that determines its Cost Code. Next plug that cost code back in to the line, write the line, move to the next line and repeat.
Below is the code snippet I have:
'***************************************************CODE START
Set oLines = oSession.AsObject(oBusObj.Lines)
retVal = oLines.movefirst() 'goto top line of details
'now loop through detail lines of order
do until cBool(oLines.EOF)
'first get item type, item #, unit price values
retval = olines.getvalue(""ItemType$"",sItemType)
retval = olines.getvalue(""ItemCode$"",sItemCode)
retval = olines.getvalue(""UnitPrice"",nUnitPrice)
'retVal = oScript.DebugPrint(nUnitPrice)
retval = olines.getvalue(""CostCode$"",sCostCode)
retval = olines.getvalue(""CostType$"",sCostType)
retval = olines.getvalue(""WarehouseCode$"",sWhsecode)
retVal = oScript.DebugPrint(""Item Detail found "" & sItemCode)
retval = oscript.debugprint(""CostCode = "" & sCostCode)
retval = oscript.debugprint(""CostType = "" & sCostType)
retval = oscript.debugprint(""warehouse is "" & sWhsecode)
'now set the cost type and cost code
Set oWhse = oLINES.AsObject(olines.GetChildHandle(""WarehouseCode""))
sWhseCostCodeUDF = """"
retVal = oWhse.GetValue(""UDF_WHCOSTCODE$"", sWhseCostCodeUDF) 'get the value of the UDF here - UDF name likely will be different on live data!
retval = olines.setvalue(""CostCode$"",sWhseCostCodeUDF)
retval = olines.write() 'finally! Write the line back
retval = olines.movenext()
loop
'****************************************CODE END
I think I have something wrong with the child handle part of getting the udf. It seems to not be grabbing the line level warehouse code. Originally i had the line reading: Set OWhse = oBusObj.AsObject(olines.getchildhandle(""warehousecode"")) but that didnt work either.
Seems like this part is where the problem is:
Set oWhse = oLINES.AsObject(olines.GetChildHandle(""WarehouseCode""))
sWhseCostCodeUDF = """"
retVal = oWhse.GetValue(""UDF_WHCOSTCODE$"", sWhseCostCodeUDF) 'get the value of the UDF here - UDF name likely will be different on live data!
I removed those three lines, and put in a 'manual' assignment to see if i was inserting the data to the cost code field incorrectly, but this works as expected:
if sWhsecode = ""VAB"" then
retval = olines.setvalue(""CostCode$"",""SVCANDY"")
retval = oscript.debugprint(""IN VAB Loop"")
end if
any ideas?
Thank you,Marc