Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

SAP Screen Personas


 

Scripting: onSelect - Use Dropdown Listboxes to streamline text input


SAP SCREEN PERSONAS KNOWLEDGE BASE - by Clemens Gantert , Regina Sheynblat , Sebastian Steinhauer

Purpose

SAP Screen Personas 3.0 does allow you to trigger scripts on each change of a Dropdown Listbox value.
This article gives a quick explanation of the event, and a small example of how to use it.

Overview

The following section will describe when the event is fired, and how you can use it.

Please note that event used in this articel, GuiComboBox.onSelect has changed significantly between SP01 and SP02. The article was updated to reflect these changes.

When is onSelect triggered?

The onSelect event is available for Dropdown Listboxes. The assigned script is executed when a user changes the selected entry in the dropdown listbox . It is not fired if a script triggers a change of a Dropdown Listbox selection.

How do I get access to the key?

In SP01: When onSelect is triggered it automatically provides a variable in the script named "key". This variable always contains the key of the selected Dropdown Listbox entry. Also "source.key" or "session.findById('ddlb_id').key" will contain the newly selected key.

In SP02: When onSelect is triggered it automatically provides a variable in the script named "newKey". Note that "source.key" or "session.findById('ddlb_id').key" contain the previously selected key, not the new key.

Example SP01

// enter key from Dropdown Listbox into User name field
session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").text = key;

Example SP02

// enter key from Dropdown Listbox into User name field
session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").text = newKey;

How to replace a text field with an Dropdown Listbox and a script ?

A very common usecase for Dropdown Listboxes with onSelect scripts is replacing an input field with a Dropdown Listbox.

  • Insert a new Dropdown Listbox into your flavor.
  • Define the visible values and corresponding key values that you would like to have entered into the text field
  • Save & Exit the flavor editor
  • Create a new Script, which enters the content of the variable "key" into the text field (see above)
  • Save you Script and Exit the script editor
  • Open your flavor editor and assign the script to the Dropdown Listbox inserted before (Insert->Script Events -> onSelect)
  • Hide the original text field (using the hide option on the home tab
  • Save & Exit the flavor editor

Your selection should now be reflected in the text field. To verify you can of course also leave the text field visible initially.

Difference to SAP Screen Personas 2.0

In SAP Screen Personas 2.0 it was possible to convert a text field directly into a Dropdown Listbox. While convenient this effectively limited the script to the one line script you see above. It was not possible to alter the script. 

In most cases customers requested the added flexibility to alter or augment the script. Specifically you are now able to use the selection to trigger specific actions - for example, pressing a specific button (for example: execute, or display, or change)  or to show or hide specific fields based on the selection (using the show/hide methods).

For example to jump right into "Display Users" after a selection the script would look like this:

Sample - display user on select from Dropdown Listbox
session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").text = key;
session.findById("wnd[0]/tbar[1]/btn[7]").press();

Related Content

Screenshots:

 

Related Search Terms:

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

Related SAP Notes/KBAs

http://wiki.scn.sap.com/wiki/display/Img/Available+Events+for+Scripting

Available Events in Scripting