Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting in SAP Screen Personas for Web Dynpro ABAP is offered to allow primarily automation of re-occurring or complex steps. With the current release the basic functions are available to automate the current application.

PREREQUISITES

To work with the scripting features inside Web Dynpro ABAP based applications you need to have at least SAP Screen Personas 3.0 SP01 and SAP_UI 750 SP01 installed on your system – otherwise the SAP Screen Personas functions are not enabled for Web Dynpro ABAP based applications. See note 2181980 for more details on the system requirements.

Complementing a script

In the first part of the blog the initial script was created. This script is working as long as everything runs fine – if there is some obstacle the script may fail at any point, e.g. the user has no edit rights. This should be prevented to not impact the user experience in a bad way.

There are two parts which should be added:

  • Validation of the environment, e.g. is a button available and enabled
  • Logging of the steps

The first part will ensure your script can handle unforeseen situations and the second part will make the support later on easier as meaningful information is either being put into the logging section of the scripting view or into the browser console.

Validation can be added using the attributes of the UI elements, e.g. the enabled attribute or other states which are available. All of these Boolean attributes work as true Boolean values in the scripting – means they can directly be consumed in if clauses. Additionally, the session object has a method idExists – which works much like the findById but instead of giving back the UI element it returns a true/ false whether an element with the given id is currently available.

Logging can be added using the session.utils.log method. This method expects a string message and a severity.

Applying validation and logging to our script it will look probably like this:

// UpdateProductName script

// log some information about the environment
var sEnvironmentInfo = "User: " + session.info.user + " started UpdateProductName script on server: " + session.info.applicationServer + ", client: " + session.info.client + " in application: " + session.info.applicationConfigId;
session.utils.log( sEnvironmentInfo, session.utils.LogLevel.INFO);

// check for all needed elements
if (!session.idExists("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_FPM_EDIT_1") ||
   !session.idExists("EPM_PD_OVP_HEADER_FORM_CFG.00.V_FORM.FGRP_8") ||
   !session.idExists("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_CANCEL") ||
   !session.idExists("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_SAVE")) {
    session.utils.log("Not all needed UI elements are on the page - exit processing");
    return;
}

// buffer elements for later usage
var oEditButton = session.findById("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_FPM_EDIT_1");
var oInputField = session.findById("EPM_PD_OVP_HEADER_FORM_CFG.00.V_FORM.FGRP_8");
var oCancelButton = session.findById("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_CANCEL");
var oSaveButton = session.findById("S_EPM_UX_PD_OVP.00.PAGE_HEADER.FPM_CA_TOOLBAR_SAVE");

// try to switch to edit mode
if (!oEditButton.enabled) {
      session.utils.log("Edit button not enabled");
      return;
}

oEditButton.Press();

if (oEditButton.enabled) {
      session.utils.log("Switch to edit mode failed");
      return;
}

// check if input field is available
if (!oInputField.enabled || oInputField.readOnly) {
      session.utils.log("Input field for product name not open for changes");
      return;
}

var sOldName = oInputField.value;
session.utils.log("Old Poduct Name: " + sOldName, session.utils.LogLevel.INFO);

var sNewName = session.utils.prompt("Enter a new product name", sOldName);
// check for user cancel action or not changed values
if (sNewName === null || sNewName === "" || sNewName === sOldName) {
      session.utils.log("Input canceled by user or name not changed", session.utils.LogLevel.INFO);
      if (oCancelButton.enabled) {
            oCancelButton.Press();
      } else {
            session.utils.log("Cancel button not enabled")
      }
      return;
}

// update product name
session.utils.log("New Product Name: " + sNewName, session.utils.LogLevel.INFO);
oInputField.value = sNewName;
if (oSaveButton.enabled) {
      oSaveButton.Press();
} else {
     session.utils.log("Save button not enabled");
     return;
}

// after save validation
if (!oSaveButton.enabled) {
      session.utils.log("Data saved", session.utils.LogLevel.INFO);
} else {
      session.utils.log("Changed data could not be saved");
}

The log output after a run from the scripting view.

In case the script is not running from the scripting view the messages could be found in the browser console instead.

Conclusion

Scripting inside SAP Screen Personas for Web Dynpro ABAP offers quite some capabilities for automation – however for more complex scenarios the development of scripts is very similar to application development.