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
___________________________