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:

  1. Launch SAP Screen Personas.
  2. Select your custom flavor, then click Scripting (see Figure 14.27).
    Scripting

    Figure 14.27    Scripting

  3. Click inline image to create a new script, enter a script name (for example: SalesOrder_Lookup) and press (Enter) (see Figure 14.28).
    Creating New Script

    Figure 14.28    Creating New Script

  4. Click Start Recording in the script window, this captures the screen actions that you perform in the following steps.
  5. 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).
    Recording Events

    Figure 14.29    Recording Events

  6. 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);
  7. 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);
    Captured Transaction Code Event

    Figure 14.30    Captured Transaction Code Event

  8. Click the Object Selectorinline image from the Inspector tab, then click the NetValue field (see Figure 14.32).
  9. Grab the text field by clicking inline image next to the text field (see Figure 14.31)
    Text Field

    Figure 14.31    Text Field

  10. 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.

    Object Selector

    Figure 14.32    Object Selector

  11. Again, with the object selector, select the currency field USD (see Figure 14.33), then click inline imageto capture the text. Define the SONetCur variable.
    Net Value’s Currency

    Figure 14.33    Net Value’s Currency

  12. 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;
  13. Navigate back to the initial screen, and click Stop Recording.
  14. We defined text input fields in the previous section; now, click inline imageObject Selector, then select the input field in Sales Order Lookup box (see Figure 14.34).
    Sales Order Lookup

    Figure 14.34    Sales Order Lookup

  15. Click inline image to capture the user’s sales order number input.
  16. Now, assign the selection to the SONumber variable.
  17. 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;
  18. 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;
  19. 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;
    Capturing Text Box to Pass Net Values

    Figure 14.35    Capturing Text Box to Pass Net Values

    Capturing Text Box to Pass Net Value’s Currency

    Figure 14.36    Capturing Text Box to Pass Net Value’s Currency

  20. 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;
  21. Click inline image to save the script.
  22. Validate the script by clicking inline image, and make sure there are no errors.
  23. Now, let’s test the script. Enter a sales order number, and click Execute.
  24. You should now see the net value and the currency displayed in the text boxes (see Figure 14.37).
    Execute Script

    Figure 14.37    Execute Script

Now, we’ll enable the Go button to run the script we created in the previous steps.

  1. To start, select the Go button, and navigate to Events • Script Events • onClick (see Figure 14.38).
  2. Select the SalesOrder_Lookup script we created in the previous steps (see Figure 14.38).
    Script Events, onClick

    Figure 14.38    Script Events, onClick

  3. Save, then Exit. You should now be able to check the net values and currency of a particular sales order (see Figure 14.39).
Custom Easy Access Screen Personas Flavor

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.