I have been working on a script for a customer that had JobOps to add some surcharges based on the lines that are in the Sales Order. They want to have the script recalculate based on changes made to the order so I used the method where you have it delete the line, recalculate, and reinsert. Script would work great, except with JobOps you get data validation errors when deleting a line this way. Any ideas on reworking this to recalculate the line and overwrite instead of deleting?
'This script adds lines to the order based on totals of other items on order
JobType = ""
ExtAmt = 0
ItemType = ""
ItemCode = ""
QtyOrd = 0
TotExt = 0
Override = ""
MiscType = ""
retVal = oBusObj.GetValue("JT158_WTClass$",JobType)
if JobType <> "SER" then
Exit Sub
End if
Set oLines = oBusObj.AsObject(oBusObj.Lines)
retVal = oLines.MoveFirst()
Do Until CBool(oLines.EOF) = True
retVal = oLines.GetValue("ItemCode$", ItemCode)
retVal = oLines.GetValue("UDF_OVERRIDE$",Override)
If ItemCode = "/HAZWASCHG" and Override = "Y" then
exit Sub
End if
If ItemCode = "/HAZWASCHG" and Override = "N" then
retVal = oLines.Delete()
End If
retVal = oLines.MoveNext()
Loop
retVal = oLines.MoveFirst()
Do Until CBool(oLines.EOF) = True
set oItem = oLines.AsObject(oLines.GetChildHandle("ItemCode")
retVal = oItem.GetValue("UDF_LAB_SUPPLY$",MiscType)
if MiscType = "Labor" then
retVal = oLines.GetValue("ExtensionAmt", ExtAmt)
TotExt = TotExt + ExtAmt
End if
retVal = oLines.MoveNext()
Loop
retVal = oLines.AddLine(
)retVal = oLines.SetValue("ItemCode$","/HAZWASCHG")
if TotExt <= 900 then
retVal = oLines.SetValue("QuantityOrdered", TotExt)
else
retVal = oLines.SetValue("QuantityOrdered", 900)
end if
retVal = oLines.Write()
------------------------------
Jesse Braun
------------------------------