Scripting

  • 1.  Sales Order Lines Script Alert when an item is on

    Posted 05-09-2017 22:03
      |   view attached
    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

    Attachment(s)

    pdf
    SO_Script_Issue.pdf   359 KB 1 version


  • 2.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-10-2017 06:09
    Are you Column PostValidating with SO_SalesOrderDetail.ItemCode? You may want to clean the objects up at the end, but I'm not sure why that would change the behavior between versions. I would add a ton of Debug.Prints and check the Trace Window to see where/when it's creating those new orders (which makes NO sense to me since there's not a single Write() anywhere...).


  • 3.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-10-2017 06:16
    I agree with @SteveIwanowski , i briefly looked at this and didn't see any Write()s, but i have seen some weird behavior on v2014 between the first time the script was triggered and all subsequent triggers, back then, i think i solved it by passing my existing object handle as a string using oScript.SetStorageVar and oScript.GetStorageVar. Near the beginning of the script, i would check if the storage variable held a value and if so, there was no need to GetObject again, i just used AsObject to set it.


  • 4.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-10-2017 06:29
    Side note, I have stopped doing my AsObject and GetObject on the same line, I also prefix my variable names with a single letter to indicate what datatype I intend to use it for. For Example, nCIItemSvc = 0 nCIItemSvc = oSession.GetObject(""CI_ItemCode_Svc"") ' Performing the below check also allows you to make sure the handle to the object was created. if nCIItemSvc > 0 then set oCIItemSvc = oSession.AsObject(nCIItemSvc) ' Do routine ' Now somewhere I believe I have seen someone say that if running a UDS or button script you don't need to ""Drop"" the object but I've gotten in the habit of dropping objects anyway as long as I created the object. If you try to do oSession.DropObject(oCIItemSvc) which is an object, you will get an error but you can use this method on nCIItemSvc. This is another reason I prefer to use a different variable name to hold the handle reference. oSession.DropObject(nCIItemSvc) set oCIItemSvc = nothing end if I'm sure another more experienced scripter can weigh in on the best practice though.


  • 5.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-10-2017 09:46
      |   view attached
    I do not believe it is Column PostValidating. I did not write the script and I am in beginner phases of scripting. I am willing to pay for assistance of someone making changes to the script for me to try.

    Attachment(s)

    docx
    SO_Script_Setup.docx   102 KB 1 version


  • 6.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-10-2017 10:54
    Can you hit Print on that User-Defined Script Maintenance screen and then upload a PDF here? That will tell us the Table/Event/Field and if there are other scripts that could be affecting the behavior.


  • 7.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-10-2017 11:32
      |   view attached
    Attached and it is PostValidating on the Item Code.

    Attachment(s)

    pdf
    Script_Listing.pdf   31 KB 1 version


  • 8.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-11-2017 22:43
    There are a couple things there different from what I would expect. First comment out the line at the end where the MessageBox appears (normally I would say substitute with DebugPrint) then recompile the script, close SO Entry and try to duplicate the issue. Although no alert will appear See if the order stays open and behaves as expected. If it appears to work now then these are the changes I suggest : 1) On the 2 lines where you see CHR(13) & CHR(10), replace it with vbCRLF 2) On the MessageBox line remove the Style=O, Then recompile, close SO Entry and try again.


  • 9.  RE: Sales Order Lines Script Alert when an item is on

    Posted 05-12-2017 15:50
    Thanks!