Scripts Advanced Tips

Remember original values in scripts

You can configure what fields Extender tracks the original value in View Events, Scripts and Workflow. Refer to Remember Original Values For: 

Because tracking original values for all fields in all views may affect performance, you can now specify which fields you need to track in a script.

If you only need to track the original values of certain fields in a specific script, use the function rememberOriginalValue('fieldname', 'fieldname2') within a view script. This forces Extender to keep track of those fields’ original values for that script only.

Note: The value configured in View Events, Scripts and WF takes precedence. If the Remember Original Values for is set to *, then Extender will remember all fields. If it is set to DESC, and the script includes "IDCUST,NAMECUST", Extender will add both and will track "DESC,IDCUST,NAMECUST".

Copy

rememberOriginalValue

# for use in a view script on OE Order Header
# Attach to OE0520
from accpac import *

def onOpen():
    rememberOriginalValue('EXPDATE')
    return Continue

def onBeforeUpdate():
    ExpDateOrig = me.replaceFields("{ORIGINAL_EXPDATE}")
    ExpDate =  me.get("expdate")
    rvspyTrace("ExpDateOrig=" + ExpDateOrig + ", ExpDate=" + ExpDate)
    return Continue

Python environment

As of PU11.00, view scripts can share a python interpreter. Shared environments are faster.

When using shared environments, the onOpen function needs to return a class. See example below.

You specify which environment you want your script to run in using env(environment_name) at the top of the script.

If there is no env line then the script will get its own interpreter.

If script A has env(env1), and script B and C have env(env2)

then all instances of script A will run in env1,

and all instances of scripts B and C will run in env2.

To use

Add a env line in the script

#@ env(environment_name)

Copy

Using Shared Environment in a view script

#@ env(environment_name)

from accpac import *

class MyView(View):
    def __init__(self):
        View.__init__(self)

    def onBeforePut(self, e):
        rvspyTrace(getMyRotoID() + " put to " + e.field)
        if e.field == "CUSTOMER":
            rvspyTrace("Changing CUSTOMER from " + self.get("CUSTOMER") + " to " + e.value)
        return Continue

# onOpen is called when the view is opened.
# Return an object to enable the macro.
# Return 0 to disable the macro.
# If you return anything else then the view will not load.
def onOpen():
    return MyView()

Tip: Create a new view script in Extender Views to get an example as above