Sales Order Lines Script Alert when an item is on another Sales Order for the same customer
The below script worked fine in version 2015 advanced on the SO Order lines tab and now sometimes causes issues in version 2016. The script provides an alert when the same item is entered on another sales order for the same customer. It works fine on the first item entered that is on another sales order, then when a second item number is entered that is on another sales order for the same customer the sales order closes and creates a blank record in sales order entry. Screen shots of more detailed information are attached. I'm trying to figure out why the script used to work and now it does not. The blank sales orders will indicate the item is on a sales order even though the customer is blank.
'***************************************************************
' only process standard orders
'***************************************************************
rc = 0
ordType = """"
rc = oHeaderObj.GetValue(""OrderType$"", ordType)
if ordType <> ""S"" then
exit sub
end if
'***************************************************************
' set object handles
'***************************************************************
oUI = 0
oSO = 0
oSOD = 0
oDays = 0
Set oUI = oSession.AsObject(oSession.UI)
Set oSO = oSession.AsObject(oSession.GetObject(""SO_SalesOrder_bus""))
Set oSOD = oSO.AsObject(oSO.Lines)
Set oDays = oSession.AsObject(oSession.GetObject(""CM_UDTMaint_bus"", ""SO_UDT_Date_Control""))
'***************************************************************
' get days from UDT
'***************************************************************
days = 0
rc = oDays.SetKeyValue(""UDF_KEYID$"",""LIST_QUOTES"")
rc = oDays.Find()
rc = oDays.GetValue(""UDF_DAYS_VALUE"",days)
'***************************************************************
' get header info
'***************************************************************
div = """"
cust = """"
shpTo = """"
ordDate = """"
itm = """"
rc = oHeaderObj.GetValue(""ARDivisionNo$"", div)
rc = oHeaderObj.GetValue(""CustomerNo$"", cust)
rc = oHeaderObj.GetValue(""ShipToCode$"", shpTo)
rc = oHeaderObj.GetValue(""OrderDate$"", ordDate)
rc = oBusObj.GetValue(""ItemCode$"", itm)
'***************************************************************
' find quotes for div/cust/ship to
'***************************************************************
begKey = """"
endKey = """"
rFilter = """"
items = """"
keys = """"
begKey = div & cust
endKey = begKey & chr(254)
rFilter = ""OrderType$="" & chr(34) & ""Q"" & chr(34) & "" and ShipToCode$="" & chr(34) & shpTo & chr(34)
rc = oSO.GetResultSets(""SalesOrderNo$"", ""SalesOrderNo$"", items, keys, rFilter, begKey, endKey, ""KCUSTOMER"", 1)
if rc = 0 then
exit sub
end if
'***************************************************************
' process quotes with matching item numbers
'***************************************************************
msg = """"
msgBtn = """"
slsNo = """"
qOrdDate = """"
qExpDate = """"
aKeys = Split(keys, CHR(138))' put keys into array
cnt = UBound(aKeys)' number of sales orders
for i = 1 to (cnt - 1)
begKey = aKeys(i)
endKey = begKey & chr(254)
rFilter = ""ItemCode$="" & chr(34) & itm & chr(34)
rc = oSOD.GetResultSets(""SalesOrderNo$"", ""SalesOrderNo$"", items, keys, rFilter, begKey, endKey, ""KPRIMARY"", 1)
if rc = 1 then
rc = oSO.SetKeyValue(""SalesOrderNo$"",aKeys(i))
rc = oSO.Find()
rc = oSO.GetValue(""SalespersonNo$"", slsNo)
rc = oSO.GetValue(""OrderDate$"", qOrdDate)
rc = oSO.GetValue(""ShipExpireDate$"", qExpDate)
rc = oSession.FormatDate(qExpDate, qExpDate, ""%Y-%M-%D"")
qExpDate = DateAdd(""d"", days, qExpDate)
qExpDate = oSession.GetFormattedDate(CStr(qExpDate))
if ordDate >= qOrdDate and _
ordDate <= qExpDate then
qOrdDate = mid(qOrdDate,5,2) & ""-"" & right(qOrdDate,2) & ""-"" & left(qOrdDate,4)
qExpDate = mid(qExpDate,5,2) & ""-"" & right(qExpDate,2) & ""-"" & left(qExpDate,4)
if len(msg) = 0 then
msg = ""Order# Sls# OrdDate ExpDate"" & chr(13) & chr(10)
end if
msg = msg & aKeys(i) & "" "" & slsNo & "" "" & qOrdDate & "" "" & qExpDate & chr(13) & chr(10)
end if
end if
next
'***************************************************************
' All Done
'***************************************************************
if len(msg) > 0 then
msgBtn = oUI.MessageBox("""",msg,""style=O,title=Related Quotes"")
end if