SAP Screen Personas
Create: Sebastian Steinhauer
Last Update: Tamas Hoznek
Scripting: onBeforeRefresh - Running your scripts on screen events
SAP Screen Personas 3.0 does allow you to trigger your scripts on each screen refresh. It also allows you to interrupt the screen update cycle.
This article gives a quick explanation of the event, and a small example of how to use it.
The following section will describe when the event is fired, which variables it provides you for your script, and how you can use it.
When is onBeforeRefresh triggered?
The assigned script is executed after a dynpro control has triggered a roundtrip. It is not fired if a script triggered the roundtrip implicitly for example by invoking the GuiButton.press() method. Furthermore, technical events such as a window resize, data provider reloads and others will not trigger this event.
Differentiating between tiggerTypes
Since onBeforeRefresh is a screen event, it only exists once per screen. Hence you need to identify the original event type in case you only want to trigger your script actions under certain conditions. In order to facility this a number of variables are pre-populated with specific values:
The parameter 'triggerType' contains a numeric differentiator between the various possible triggers. Possible trigger type values are defined as constants for all window objects. Currently supported types also exist as constants are: source.EVENT_VCOMP, source.EVENT_VKEY, source.EVENT_ENTER.
The parameter 'caller' contains the triggering object if the triggerType was EVENT_VCOMP.
The parameter 'vkey' contains a valid function key if the triggerType was EVENT_VKEY.
Please note, the parameters are only defined when the script is executed triggered by the onBeforeRefresh event. If you execute your script in the script editor by clicking the 'Execute' button then a script like the one above will fail because triggerType is not a valid.
Stopping the round-trip
Please note, if you are not returning true then the command/action that was trigger is executed after your script is executed, therefore, please make sure that the screen is in a valid state e.g. if your script navigates to a different screen or opens a popup and your script does not return true, then it is very likely that you get an error popup with a 'control not found' error.
Related Search Terms:
SAP Screen Personas, onBeforeRefresh, Events, Event, Scripting, input validation