Additional Blogs by SAP
Showing results for 
Search instead for 
Did you mean: 
Product and Topic Expert
Product and Topic Expert
0 Kudos

As I have been demoing SAP Screen Personas 3.0 at TechEd, ASUG, and to individual customers, people are impressed by the power and ease of use of the new scripting engine. My usual demo shows how to improve productivity by eliminating keystrokes or bringing information from multiple transactions onto a single screen. I documented how easy this in my first JavaScript primer.

Here is the starting screen.

When I enter my user name into the center box and click the script button (large yellow square), the system

  1. goes to SU01
  2. types my name into the name box
  3. clicks on the glasses button
  4. retrieves my name from the address tab
  5. comes back to the start screen
  6. writes the result into the window

When you enter a name in the box, the script works perfectly every time. The problem arises when I forget to enter a name and click the button. It jumps to the first screen of SU01 and waits for the name. From an audience perspective, it looks like the script failed. For me, this is embarrassing, especially during a live demo to a large group.

Fortunately, there is an easy fix. Have the script check that the box is not empty prior to jumping to another transaction. But, this requires another JavaScript command, the IF statement. Like setting a variable, the syntax is very easy.

This is the part of the script that checks to make sure the box is not empty:

var user = session.findById("wnd[0]/usr/txtPersonas_7").text;

if (!user) {

     session.findById("wnd[0]/usr/lblPersonas_9").text = "enter name";



Let’s look at the different elements in the script.

  • We define a variable called "user" that contains the contents of the text box in the top middle.
  • The “!” means not. So, the if statement in the second line of the script is seeing if there is a value for “user”.
  • If there is any text in the box, (user) will be true.The script will skip over anything inside the if condition.
  • If the text box is blank, (user) will be false, and (!user) will be true. The script will run.
  • If the code inside the if condition runs, the script will write the warning message “enter name” in the box where the name will eventually go if the script executes correctly.
  • The return statement says to end the script and not jump to the next step after the if condition.

The JavaScript IF statement is a great way to trap errors in SAP Screen Personas.

Good luck with your scripting!

For the SAP Screen Personas product team, peter.spielvogel.