Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

SAP Screen Personas


 

Experimental Feature: Scheduling scripting tasks to be executed asynchronously


SAP SCREEN PERSONAS KNOWLEDGE BASE - by Clemens Gantert , Regina Sheynblat

As of SP06 this article is obsolete. Please refer to the new Knowledge Base article on executeScriptAsync method.

Purpose

A new experimental scripting feature is described. It allows for breaking up long running scripts into smaller chunks that are executed asynchronously and can update the screen with progress information when they are finished.

 

This article describes an experimental feature.

The feature described in the article was introduced with Service Pack 3 of SAP Screen Personas 3.0

Consider that:

  1. It only works in the SAP GUI for Html. It is not supported in the SAP Gui for Windows or Java
  2. The described API may be changed or even removed in future releases of SAP Screen Personas

 

Overview

Long running Personas scripts, which may block the UI for many minutes, can be split into smaller, shorter running tasks and scheduled to be executed one after the other. When a task is complete, the screen is redrawn allowing for progress information to be shown.

Breaking up long-running scripts into smaller, asynchronously executed tasks

The problem: You have personas script that takes tens of seconds to minutes to complete. While the script executes the UI is blocked and except for the loading animation the user has no indication of what is happening. There is no progress information. To make matters worse many older kernels do not even show the loading animation during script execution.

The solution is to break up the script into smaller tasks that are scheduled and that at the end of their execution update the screen with progress information. Please note that this will work on scripts that can be broken up into tasks, such as when a list of documents or objects is processed one at time. If your long-running script just presses a standard button that then will start the standard button action which happens to take very long then the outline approach will of course not work.

API method sap.personas.scripting.scriptingEngine.scheduleTask( fTask ) and Usage Examples

There is a new scripting method sap.personas.scripting.scriptingEngine.scheduleTask( fTask ). Its only parameter is a JavaScript function. When you call it in your script it just schedules your task to be executed. The calling script continues executing. When it finishes, the screen is redrawn (incl. onAfterRefresh scripts) and then the first scheduled task is executed. When this first task is finished the screen is refreshed again (and onAfterRefresh scripts executed) and the next scheduled task is executed, and so on.

The following simple example

sap.personas.scripting.scriptingEngine.scheduleTask(
	function() {session.utils.log("1");}
);
sap.personas.scripting.scriptingEngine.scheduleTask(
	function() {session.utils.log("2");}
);
session.utils.log("3");

shows the following log:

3
1
2

 

Within your tasks functions you have access to the session variable and can do anything a "normal" script can do, up to manipulating UI elements to give a progress update to the user. When writing your script it is key that each task function "knows" which step and what data to work. This can be achieved with "global" variables defined in the original script or by packing the data into closure of the task script.

Example 1: All tasks are scheduled in the original script. Each task waits 3s and then appends a task string to a multi-line label.

var taskStrings = ["first step", "second step", "third step"];
var text ="";
var index = 0;
var fTask = function (){
	// 3s pause
	var time = (new Date()).getTime() +3000;
	while ((new Date()).getTime() < time ); 
	//update the UI
	text += taskStrings[index++] + " completed.\n";
	session.findById("wnd[0]/usr/wlblPersonas_1453929017141").text =text;
};

for (var i=0; i<taskStrings.length;i++){	
	sap.personas.scripting.scriptingEngine.scheduleTask(fTask);
}
session.findById("wnd[0]/usr/wlblPersonas_1453929017141").text = "";

The above example works because the variables taskStrings and index exist for every task and during the entire life time of the process. When one task finishes it increases the "global" variable index.

It might be cleaner to pack the data into the closure of each task as done in Example 2, but this does not make such a script easier to read and understand.

Example 2: If does the same thing as Example 1, but data is encapsuled in each task.

var taskStrings = ["first step", "second step", "third step"];
var text ="";
var fTask;
var currText;
for (var i=0; i<taskStrings.length;i++){
	
	(function(){
			var currTaskText = taskStrings[i];	
			fTask= function (){
				// 3s pause
				var time = (new Date()).getTime() +3000;
				while ((new Date()).getTime() < time ); 
				//update the UI
				text += currTaskText+ " completed.\n";
				session.findById("wnd[0]/usr/wlblPersonas_1453929017141").text =text;
		};	
		sap.personas.scripting.scriptingEngine.scheduleTask(fTask);
	})();
}


session.findById("wnd[0]/usr/wlblPersonas_1453929017141").text = "";

 

Last but not least, it is possible to schedule tasks during the execution of a task.This is even required if the if task 2 depends on data or results of task 1.

var taskStrings = ["first step", "second step", "third step"];
var index =0;
var text ="";
function fTask(){
	// 3s pause
	var time = (new Date()).getTime() +3000;
	while ((new Date()).getTime() < time ); 
	
	//update the UI
	text += taskStrings[index]+ " completed.\n";
	session.findById("wnd[0]/usr/wlblPersonas_1453929017141").text =text;
	// schedule the next task
	if (++index < taskStrings.length){
		sap.personas.scripting.scriptingEngine.scheduleTask(fTask);
	}	
}
sap.personas.scripting.scriptingEngine.scheduleTask(fTask);

 

Related Content

Related Search Terms:

SAP Screen Personas, Script, Scripting, asynchronous, scheduling

Related SAP Notes/KBAs

N/A

 

 

 

 

Important News

This knowledge base is not solely SAP provided content - but community driven. Please also check on SMP and help.sap.com for SAP released information and notes on SAP Screen Personas.

Create New Article

Compare SAP Screen Personas versions

Search the KB

How to Open OSS Message

 What information is needed for creating OSS message?

  1. Make Sure you are on the latest patches and notes.
  2. Kernel Patch Level
  3. Two Types of connections to your environment: HTTP and R/3
  4. All the connections should be tested with proper credentials provided
  5. Steps to re-create the issue
  6. Attach related logs
  7. File tickets against BC_PER