Scripting

  • 1.  I need to revise an existing button script in the

    Posted 06-13-2017 17:22
      |   view attached
    I need to revise an existing button script in the Sales Order Header as follows. Add script to populate an UDF_POPlacedDate with today's date. The UDF so far has been manually entered by users whenever they click the button. The problem is they often forget to revise the date in the UDF. The orders can be new or existing. (Background on the existing script when users click the button, it writes certain SO info to the client's website.) I need the revised script to first revise the UDF_POPlacedDate to today's date, then update the web with all the SO info including the revised date. I have tested a separate button to successfully populate the UDF but I have to click the Accept button to save it to SOHeader. If I add the ""retVal=oBusObj.Write()"" line, the entire order is hung up. Is there a way to resolve this?

    Attachment(s)

    txt
    POPlacedDate.txt   825 B 1 version


  • 2.  RE: I need to revise an existing button script in the

    Posted 06-13-2017 17:42
    An oBusObj.Write() is only needed for the lines object. It is not needed for the header.


  • 3.  RE: I need to revise an existing button script in the

    Posted 06-13-2017 17:52
    So how do I write to the SOHeader file?


  • 4.  RE: I need to revise an existing button script in the

    Posted 06-13-2017 20:58
    Check that the return code (retVal) from the SetValue is 1 and your change to the header should be complete once the Accept button is clicked.


  • 5.  RE: I need to revise an existing button script in the

    Posted 06-13-2017 21:04
    I tested it, the user has to click ""Accept"" to save it to SOHeader. In this case, the user can be clicking ""Cancel"" because he is just opening the SO to click the Update to Web button.


  • 6.  RE: I need to revise an existing button script in the

    Posted 06-13-2017 22:23
    retVal = oBusObj.Write() after an oBusObj.SetValue works for me without hanging anything. Another work around (since Write does the same thing as Accept, except for staying in the order) would be: Set oShell = CreateObject(""WSCript.Shell"") oShell.SendKeys(""%a"") ' Invoke Accept button oShell.SendKeys(SO_SalesOrder_bus_SalesOrderNo) ' Enter order number oShell.SendKeys(""~"") ' Simulate pressing Enter key and voila - your still in the same order You will need to select the 'SO_SalesOrder_bus_SalesOrderNo' variable to be added to the button script in ""Link Settings


  • 7.  RE: I need to revise an existing button script in the

    Posted 07-14-2017 19:31
    a safer way to achieve this would be the following _________________________________ nRetval = 0 sSalesOrderNo = """" nRetval = oBusObj.GetValue(""SalesOrderNo$"", sSalesOrderNo) oBusObj.LastErrorMsg = """" ' ### We are setting to blank because we do not want to invoke the change on the sales order number if there is a field that fails validation, if a field were to fail validation and you call InvokeChange, the user will lose any changes to the order. This is especially bad if it is a new order, they lose EVERYTHING. nRetval = oUIObj.BT_Accept() ' ### Invoke the accept button using the UI object's method. ' ### Below, we check to see if any errors were set when we invoked the accept button. if oBusObj.LastErrorMsg = """" then nRetval = oUIObj.InvokeChange(""SalesOrderNo"", sSalesOrderNo) ' ### this has the same effect as keying in the sales order manually. end if


  • 8.  RE: I need to revise an existing button script in the

    Posted 07-19-2017 11:09
    The above was something i typed up out of memory from a v2014 project with more complicated criteria. I just got around to actually needing this in v2017 and while testing the above in v2015, i was getting very inconsistent results from the LastErrorMsg property on the oBusObj and oLines objects so it may not work well if you need to re-display the sales order, it will work fine for ""attempting to save"" the order via the BT_Accept() method but you probably will never get the sales order re-displayed. For anyone who actually needs the sales order re-displayed after a successful write triggered by a button script, the below should do the trick. It is one script set to run on the button and also on the table's PostWrite event. _________________________ If UCase(oScript.GetCurrentProcedure()) = ""POSTWRITE"" Then nRetval = 0 sSalesOrderNo = """" : nRetval = oSession.AsObject(oSession.ScriptObject).GetStorageVar(""sSalesOrderNo"", sSalesOrderNo) If sSalesOrderNo <> """" And oScript.UIObj > 0 And UCase(oSession.StartProgram) = ""SO_SALESORDER_UI"" Then nRetval = oSession.AsObject(oSession.ScriptObject).SetStorageVar(""nRedisplay"", 1) End If nRetval = oSession.AsObject(oSession.ScriptObject).SetStorageVar(""sSalesOrderNo"", """") ElseIf UCase(oScript.GetCurrentProcedure()) = ""0"" And IsObject(oUIObj) Then nRetval = 0 sSalesOrderNo = """" : nRetval = oBusObj.GetValue(""SalesOrderNo$"", sSalesOrderNo) nRetval = oSession.AsObject(oSession.ScriptObject).SetStorageVar(""sSalesOrderNo"", sSalesOrderNo) nRetval = oUIObj.BT_Accept() nRedisplay = 0 : nRetval = oSession.AsObject(oSession.ScriptObject).GetStorageVar(""nRedisplay"", nRedisplay) If nRedisplay = 1 Then nRetval = oUIObj.InvokeChange(""SalesOrderNo"", sSalesOrderNo) End If nRetval = oSession.AsObject(oSession.ScriptObject).SetStorageVar(""sSalesOrderNo"", """") nRetval = oSession.AsObject(oSession.ScriptObject).SetStorageVar(""nRedisplay"", 0) End If ___________________________