Page tree
Skip to end of metadata
Go to start of metadata

SAP Screen Personas

Scripting: onBeforeRefresh - Running your scripts on screen events

SAP SCREEN PERSONAS KNOWLEDGE BASE - by Tamas Hoznek , Regina Sheynblat , Sebastian Steinhauer


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 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.


// ignore event if not onEnter 
if (triggerType !== source.EVENT_ENTER){ 
    //let round-trip pass
} else {
     if (session.findById('wnd[0]/usr/txtPersonas_2').text.length===0){
        //no data provided show error in console
        session.utils.log("Detected missing value");
        //stop round-trip 
        return true;

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

If the associated script returns a boolean true value, then the started roundtrip is stopped. If the script returns anything else or nothing (in javascript 'undefined'), then the started roundtrip continues normally.

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 Content


Related Search Terms:

SAP Screen Personas, onBeforeRefresh, Events, Event, Scripting, input validation

Related SAP Notes/KBAs