As part of the product team, I shared the excitement of the developers around a new, more powerful scripting engine in SAP Screen Personas 3.0 that is based on JavaScript. Like many of you who have no experience with JavaScript, I was a bit intimidated, especially by the { and } symbols, which look like serious programming. I’m pleased to report that I wrote my first (and second) script in SAP Screen Personas 3.0 - and it was much easier than I thought.
For basic scripts, I see customers doing two main things:
The only JavaScript you need for these steps is:
Using JavaScript in SAP Screen Personas 3.0 does not need to be intimidating.
If you want to know how to apply this in your scripts, keep reading. In this post, I will share with you the basic steps and JavaScript syntax you will need to move information between screens.
I built my script on the SMEN transaction, connecting it to SU01 for user information. I removed the user area and added several custom fields. Here is what it looks like.
Script Example #1 jumping to a different transaction and bringing the values back to the original screen
Each script button contains a single script. First, let’s examine the “Lookup” button. I type my user name “peter” into the text box, click the “Lookup” button, and my full name appears in the space that formerly contained firstname and lastname.
Here is the script.
Full text of the script copied from the script window for readability (includes my comments).
// copy name from text box; assign to variable "uname"
var uname = session.findById("wnd[0]/usr/txtPersonas_3").text;
// enter SU01 into OKcode field, type enter, paste name on SU01, click lookup button
// define variables for first name and last name
var fname = session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_FIRST").text;
var lname = session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").text;
// return to SMEN transaction
// {"eventName":"Enter","tcode":"SU01","screen":"1100","controlCustomData":{"SID":"wnd[0]/tbar[0]/okcd","Type":"GuiTextField"},"eventParas":{"Id":"ToolbarOkCode"}}
Most of this JavaScript code (not the comments) was auto generated by SAP Screen Personas.
Here is what I did:
Do the same for the last name field (not pictured).
JavaScript that you need to learn:
Define a variable for each of these values to replace the fixed text.
Simply add “Var yourvariablename = “ to the beginning of the line (blue text).
Remove the stored value from the end of the line (red text).
Start:
End:
var lname = session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").text;
Then, continue recording and return to your SMEN transaction.
Pause recording and use the Inspector to add the custom text fields that will receive your pasted values to your script.
JavaScript #2 that you need to learn:
Replace the fixed text value with your variable name.
Start:
End:
You have replaced the initial value in the text field (red text) with the variable name (blue text). Please note that the quotation marks around the original text are gone when you replace it with the variable name.
That’s it for the first scripting example. Two easy changes to the text. And, no messy curly braces {}.
Script Example #2 copying information from one screen and pasting it on another
This script takes the name from the custom input field and then goes directly to the information tabs in SU01, bypassing the initial screen in which you generally enter the user name and click the glasses to look up information (thereby saving keystrokes).
Start:
End:
We skip over this screen entirely (streamlining the process for users):
The JavaScript is even simpler than the other example and introduces no new syntax.
Here is the text of the script:
// copy user name from screen
var user = session.findById("wnd[0]/usr/txtPersonas_3").text;
// enter SU01 into OKcode field
// press enter
// "paste" user name captured from original screen
// press "glasses" button to lookup user
So, the essential JavaScript code you need to know for both of these use cases is:
“var yourvariablename = “
Also removing hardcoded values and replacing them with your variable names.
In a future post, I’ll explore the IF statement and how to use it.
For the SAP Screen Personas product team, peter.spielvogel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
32 | |
14 | |
13 | |
13 | |
11 | |
8 | |
8 | |
7 | |
7 | |
6 |