SAP Screen Personas
Create: Clemens Gantert
Last Update: Tamas Hoznek
Change the value set of a combo box through scripting.
SAP SCREEN PERSONAS KNOWLEDGE BASE - by Tamas Hoznek , Clemens Gantert , Regina Sheynblat
A much asked for feature since the introduction of SAP Screen Personas 3.0 was the ability to change the value set of a combo box dynamically through scripting. With SP03, this feature has become a reality.
A how to guide is provided explaining the differences between standard and custom combo boxes. For the typical use cases, sample scripts are provided.
Changing the value set of a combo box
If you take a look at type GuiComboBox in the API documentation, you will notice that the property "entries" was changed from read-only to "readable and writeable". The other change is that the type of the property was changed from GuiCollection to GuiComboBoxEntryCollection.
The idea is to read the "entries" property, then manipulate the retrieved GuiComboBoxEntryCollection object and, finally, to reassign the manipulated collection back to the combo box's entries property.
It's important to understand that by reading the entries property you receive a "detached" collection and that only the assigning of a collection to the entries property of the combo box actually changes the value set of the combo box.
There are differences between what can be done with a custom (flavor-created) combo box and a standard (DYNPRO) combo box. Just like in the flavor editor, standard combo boxes can only be changed in the following way:
- Existing entries can be removed or hidden (use the removeAt() or removeAll() methods)
- Existing entries can be reordered (use removeAt() in conjuction with add() and addAt() )
- The label texts of existing entries can be changed by changing the "value" property of a GuiComboBoxEntry object. Note that in the flavor editor UI, every combo box entry you create for it has a "Key" and a "Label", in scripting however a GuiComboBoxEntry object has a "key" property and a "value" property, that latter corresponding to the label.
Custom combo boxes can be filled with new entries via the factory method createComboBoxEntry(String key, String value) that the GuiComboBoxEntryCollection object provides. Note that you can add entries created even to standard combo boxes provided that the key existed before (and there are no duplicate entries with the same key).
Every time you read the "entries" property you get a new GuiComboBoxEntryCollection. So, reading "entries" is like invoking a factory method for GuiComboBoxEntryCollection objects. This can be used for reordering. See script below.
In this last example we make use of the Array.sort() method with a comparison method to sort the value set in descending order of their key.
Related Search Terms:
SAP Screen Personas, Scripting, Combo Box