Prudy you're close. First of all I say get rid of the AFS because you can't fire them off conditionally and it's limited by user-company combination. For your Pre-Write script that requires a ShipVia, prior to the SetError() you can do something like this:
`
BOI = oSession.ObjectInterface
InUpdate = oSession.Updating
Security = oBusObj.SecurityAccess
StartProgram = Trim(UCase(oSession.StartProgram))
If (BOI > 0 or InUpdate > 0 or Security = 0 or StartProgram <> ""SO_SALESORDER_UI"") Then Exit Sub
`
Each of those means something very important (I would leave them all in) but the StartProgram is most relevant to you. When creating RMA Xpress sales order, the StartProgram = RA_RETURN_UI so you could simply do
If oSession.StartProgram = ""RA_RETURN_UI"" Then Exit Sub
But then there are so many other ways to create sales orders like RMA Gen, Auto Generate Orders, EDI mod, a web service that uses BOI. So better to check for <> SO_SALESORDER_UI
Hope that helps.
#ScriptingStartProgram