I am writing a script that is intended to add up particular lines on a sales order and create a new line with a miscellaneous item using the total qty shipped for those items. The script works great when it is run as a Pre-Totals on the Sales Order Header. The problem is, this client also has JobOps and I believe the JobOps functionality is interfering with the script.
When the user goes from the Work Ticket back to Sales Order, it seems to unexpectedly delete a miscellaneous item from the order/work ticket. When I figure out how to get around this with one work ticket step, it deletes a miscellaneous item on the next step. I am using this script as a Pre-Write on the Sales Order Header since the Pre Totals won't work from Work Ticket.
Here is the script:
JobType = """"
ExtAmtM = 0
ExtAmtI = 0
ItemType = """"
ItemCode = """"
QtyOrd = 0
TotExt1 = 0
TotExt2 = 0
TotExt = 0
Override = """"
MiscType = """"
ItemType = """"
sCurKey = """"
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 = ""/SUPPLCHG"" 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(""ItemType$"",ItemType)
if ItemType <> 1 then
retVal = oItem.GetValue(""UDF_LABOR_SUPPLY$"",MiscType)
if MiscType = ""Supply"" then
retVal = oLines.GetValue(""ExtensionAmt"", ExtAmtM)
TotExt1 = TotExt1 + ExtAmtM
End if
End if
retVal = oLines.MoveNext()
Loop
retVal = oLines.MoveFirst()
Do Until CBool(oLines.EOF) = True
retVal = oItem.GetValue(""ItemType$"",ItemType)
If ItemType = ""1"" then
retVal = oLines.GetValue(""ExtensionAmt"", ExtAmtI)
TotExt2 = TotExt2 + ExtAmtI
End if
retVal = oLines.MoveNext()
Loop
TotExt = TotExt1 + TotExt2
sCurKey = oLines.GetKey()
retVal = oLines.InsertLine(sCurKey, ""A"")
retVal = oLines.SetValue(""ItemCode$"",""/SUPPLCHG"")
if TotExt <= 900 then
retVal = oLines.SetValue(""QuantityOrdered"", TotExt)
else
retVal = oLines.SetValue(""QuantityOrdered"", 900)
end if
retVal = oLines.Write()