Introduction

With SAP Screen Personas there is now the option to add client-side scripting to existing Webdynpro for ABAP applications. For a first introduction to scripting please have a look at the Overview Blog of Matthias Heitmann.

With scripting it’s now possible to automate re-occurring or complex tasks. However there is a technical restriction: The script is always tied to the (technical) application. There is no possibility to define a script, which runs across different applications or even different browser windows. This heavily limits the applicability of scripting for automation.

Even worse is the fact, that there exists a lot of applications which are running in 2 windows – technically these are 2 instances of the same application. Such applications can’t be automated. Examples are basically all FPM applications based on the OVP Floorplan, which are using the Initial screen feature. A typical example is the demo application S_EPM_FPM_PD:

/wp-content/uploads/2016/07/s_epm_fpm_pd_1001607.png

This application consists of an initial page, allowing you to search for products and a main page where single products are displayed and edited. By clicking a product name in the search result list, the application will launch the main page for this product in a separate window.

Now let’s assume we want to add a “discount” feature to this application – the user shall have the option to reduce the price of the selected products by a certain percentage. With the standard functionality this is a bit cumbersome: For each product to be discounter the user has to

  1. Click the product name
  2. Wait for the new window to be opened
  3. Press the ‘Edit’ button in the new window
  4. Change the Price
  5. Press ‘Save’

Much easier for the user would be a solution where there is a ‘Discount’ button on the initial screen. After clicking this button an input dialog would appear where the user can enter the percentage value and on closing this dialog everything else will be done automatically.

With a single script automation isn’t possible. Nevertheless since SAP_UI 7.50 SP03 there is a mechanism in place allowing to solve such tasks.

Concept

The idea is simple: Instead of enabling scripts to run in 2 windows, Personas now offers the possibility to

  • start a script in the first session,
  • and specify a follow-up and a completion script when navigating to the 2nd window.
  • When the 2nd window is launched the follow-up script will be executed and
  • On completion of the script in the 2nd window the completion script will be executed in the first window

Example

I will now show and explain the scripts needed to add such a discount functionality to demo application S_EPM_FPM_PD.

We will need 3 scripts:

  1. A start script which will prompt for the discount rate and then trigger the discounting for all selected products
  2. The follow-up script which will be executed once for each product on the application’s main page. This script will calculate, change and save the new product price
  3. The complete script which will restart the search, to show the updated values

Start Script

//Determine number of visible rows (this script will only work on visible values)
var visibleRowCount = session.findById("EPM_PD_OVP_SEARCH_LIST_CFG.00.LIST_VIEW.DYNAMIC_TABLE").visibleRowCount;
var rowCount = session.findById("EPM_PD_OVP_SEARCH_LIST_CFG.00.LIST_VIEW.DYNAMIC_TABLE").rowCount;
var firstVisibleRow = session.findById("EPM_PD_OVP_SEARCH_LIST_CFG.00.LIST_VIEW.DYNAMIC_TABLE").firstVisibleRow;
var visibleRows = Math.min(visibleRowCount,rowCount-firstVisibleRow);
//If there are no visible rows return
if (visibleRows == 0) {
         session.utils.alert("No products selected!");
         return; 
}
//Create a followup object, which will be passed to the next browser session
var followup = {scriptId:"wnd[0]/scrptPersonas_1"};
//Prompt for the discount rate and store it in the followup object

followup.parameters = session.utils.prompt("Enter discount rate: ","5");
//Check if user entered a valid value
if(followup.parameters==null || isNaN(followup.parameters)==true) {
         session.utils.alert("Discount value is not a valid Number!");
         return;
}
//Loop for all visible rows and click the product name link
for(var i=firstVisibleRow;i<firstVisibleRow+visibleRows;i++)
{
         if (i==firstVisibleRow+visibleRows-1) {
                   //When the last selected line is processed, specify the complete script
                   followup.onCompleteScriptId = "wnd[0]/scrptPersonas_2";
         }
         //Click the product name and pass the followup object
         session.findById("EPM_PD_OVP_SEARCH_LIST_CFG.00.LIST_VIEW.PRODUCT_NAME_FPM_CE[" + i +"]").Activate( false, false, followup);
};





In line 14 the followup object is created which is used to pass the name of the followup and the complete script, as well as the input parameters of the followup script to the next session.  In line 34 the navigation is triggered and the followup object is passed

Follow-up Script

var discountRate = 5;
//Check if discount rate has been passed, if not prompt the user. This makes it possible to
//run and test the script standalone
if(typeof followUpParameter === 'undefined' || followUpParameter === null)
         discountRate = session.utils.prompt("Enter discount rate: ","5");
else
    discountRate = session.utils.parseFormattedNumber(followUpParameter);
debugger;
//Switch to Edit Mode
if (session.findById("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_FPM_EDIT_1").enabled)
                   session.findById("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_FPM_EDIT_1").Press();
//Get the current price
var priceString = session.findById("EPM_PD_OVP_HEADER_FORM_CFG.00.V_FORM.FGRP_12").value;
//Calculate new price...
var priceNumber = session.utils.parseFormattedNumber(priceString);
priceNumber = (100 - discountRate) * priceNumber / 100;
//round price to 2 decimals
priceNumber = Math.round(100*priceNumber)/100;
var newPriceString = session.utils.getFormattedNumber(priceNumber);
//...and write it back to the price input field

session.findById("EPM_PD_OVP_HEADER_FORM_CFG.00.V_FORM.FGRP_12").value = newPriceString;
// save
session.findById("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_SAVE").Press();



Complete Script

//After all prices have been updated re-execute the search to see the discounted
//prices in the result list

session.findById("FA35119EB8954786093E7A3C90C71FB8.07.V_SELECT_OPTIONS.BTN_SEARCH").Press();

After creating the 3 scripts there is only one thing missing: We have to add a Script Button to start the first script

/wp-content/uploads/2016/07/css_1003775.png

Summary

By passing follow-up script names when navigating to another application, it’s possible now to automate processes across different applications with Personas Scripting. This is especially helpful for all those applications starting with a search result list, where the object is edited in a seperate browser window or tab.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Won Hwang

    I tried your steps and the price gets updated correctly; however, if I have ten visible rows, I get 10 new browser windows with details of the products. Is it an expected behavior?

    (0) 
    1. Christian Guenther Post author

      Hello Won Hwang,

      yes this is ok. The blog’s intention was to demonstrate how cross-session scripting works and not to provide a production-ready script.

      Best regards,

        Christian

      (0) 
      1. Won Hwang

        Thank you for your reply Christian.

        Hope I can find more articles or document that talk about cross-session scripting. So far, I could find only your article that talks about it.

        Thank you.

        -Won

        (0) 

Leave a Reply