14.3 Advanced SAP Screen Personas Flavor Concepts
In this section, we’ll explore advanced options such as scripting. Scripting is a powerful tool that allows developers to automate or manipulate a screen action. We’ll cover some basic scripting tasks using JavaScript and show you how to create more engaging SAP screens.
In the following exercise, we’ll cover navigation of scripting windows, moving around the SAP Screen Personas script editor, and using JavaScript events to enrich screens. Follow these steps:
- Launch SAP Screen Personas.
-
Select your custom flavor, then click Scripting (see Figure 14.27).
Figure 14.27 Scripting
-
Click
to create a new script, enter a script name (for example: SalesOrder_Lookup) and press (Enter) (see Figure 14.28).
Figure 14.28 Creating New Script
- Click Start Recording in the script window, this captures the screen actions that you perform in the following steps.
-
We’ll first capture the screens of the VA03 (Display Sales Order) transaction. In the command field enter the transaction code VA03 and click the green checkbox (see Figure 14.29).
Figure 14.29 Recording Events
-
You should now see the event captured in the script window (see Figure 14.30). The following is an example of a recorded script:
session.findById("wnd[0]/tbar[0]/okcd").text = "VA03"; session.findById("wnd[0]").sendVKey(0); -
While the script window is open, enter a sales Order number, then press (Enter) (see Figure 14.30). The following is an example of a recorded script:
session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = "14800"; session.findById("wnd[0]/usr/ctxtVBAK-VBELN").setFocus(); session.findById("wnd[0]").sendVKey(0);Figure 14.30 Captured Transaction Code Event
-
Click the Object Selector
from the Inspector tab, then click the NetValue field (see Figure 14.32).
-
Grab the text field by clicking
next to the text field (see Figure 14.31)
Figure 14.31 Text Field
-
Define the SONetVal variable as follows:
Var SONetVal = session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBAK-NETWR").text; (see Figure 14.32).Important!
Remember to add a semicolon (;) at the end of every text element you capture using the object selector. If you notice in your script window ; will be missing after the .text function.
Figure 14.32 Object Selector
-
Again, with the object selector, select the currency field USD (see Figure 14.33), then click
to capture the text. Define the SONetCur variable.
Figure 14.33 Net Value’s Currency
-
The following is an example of a recorded script; remember to add ; at the end of the script:
Var SONetCur = session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBAK-NETWR").text; - Navigate back to the initial screen, and click Stop Recording.
-
We defined text input fields in the previous section; now, click
Object Selector, then select the input field in Sales Order Lookup box (see Figure 14.34).
Figure 14.34 Sales Order Lookup
-
Click
to capture the user’s sales order number input.
- Now, assign the selection to the SONumber variable.
-
Your script should look something like the following:
//Get the Sales Order # entered by the uservar SONumber = session.findById("wnd[0]/usr/txtPersonas_148764811439777").text; -
Now, pass the user-entered sales order number by using the variable we created in the previous step (see Figure 14.35):
//Pass the user entered SO Numbersession.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = SONumber; -
Similarly, capture the other two text boxes (see Figure 14.35 and Figure 14.36), and pass the variables we created, SONet and SONetCur in Steps 9 and 11:
//Fill the Netvalue and Currency fieldssession.findById("wnd[0]/usr/txtPersonas_148764813406176").text = SONetCur;session.findById("wnd[0]/usr/txtPersonas_148764812672532").text = SONetVal;Figure 14.35 Capturing Text Box to Pass Net Values
Figure 14.36 Capturing Text Box to Pass Net Value’s Currency
-
Check your final script:
//Get the Sales Order # entered by the uservar SONumber = session.findById("wnd[0]/usr/txtPersonas_148764811439777").text; //Go to Transaction VA03session.findById("wnd[0]/tbar[0]/okcd").text = "va03"; session.findById("wnd[0]").sendVKey(0); //Pass the user entered SO Numbersession.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = SONumber; session.findById("wnd[0]").sendVKey(0); //Get Netvalue and Currencyvar SONetVal = session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/ctxtVBAK-WAERK").text; var SONetCur = session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBAK-NETWR").text; //Navigate back to myEasy Access screensession.findById("wnd[0]/tbar[0]/btn[3]").press(); session.findById("wnd[0]/tbar[0]/btn[3]").press(); //Fill the Netvalue and Currency fieldssession.findById("wnd[0]/usr/txtPersonas_148764813406176").text = SONetCur; session.findById("wnd[0]/usr/txtPersonas_148764812672532").text = SONetVal; -
Click
to save the script.
-
Validate the script by clicking
, and make sure there are no errors.
- Now, let’s test the script. Enter a sales order number, and click Execute.
-
You should now see the net value and the currency displayed in the text boxes (see Figure 14.37).
Figure 14.37 Execute Script
Now, we’ll enable the Go button to run the script we created in the previous steps.
- To start, select the Go button, and navigate to Events • Script Events • onClick (see Figure 14.38).
-
Select the SalesOrder_Lookup script we created in the previous steps (see Figure 14.38).
Figure 14.38 Script Events, onClick
- Save, then Exit. You should now be able to check the net values and currency of a particular sales order (see Figure 14.39).
Figure 14.39 Custom Easy Access Screen Personas Flavor
We’ve successfully created our first screen persona flavor and then add explored some advanced scripting options as well. Next, we’ll explore the SAP Screen personas administrative tasks.