Liquid UI - WS Reference Library

WS Special Scripts


There are some special script files in WS that are entirely separate from the script files associated with the SAP dynpros. These script files are as follows.

Logon Script

The logon script runs at logon, as the name suggests. It contains anything that must be loaded or run at logon.

Session Script

The session script is very similar to the logon script, but it will run each time you launch a new session. Anything that is specific to a session would be placed in this file.

Function Script

You can place any functions that you wish to be universal to all transactions in the 'functionsSystem.sjs' script file.

Each of these script files will be explained in more detail in the following sections.


Logon Script (elogon.sjs)

The logon script file is used to contain any functions or commands that need to be loaded at logon. This file is not required for a WS implementation, but it is good practice to use it if you have elements that need to be loaded or called at logon time. Anything contained in the logon script file will be used universally in your scripts - it is not restricted to a single session. An example logon script file is shown below.

load('wsoffice');
load('functionsSystem.sjs');

function getFilesToUpload(szPrompt)
{  
    if(szPrompt==void 0) szPrompt = 'Select File';
    var dialog = new ActiveXObject('MsComDlg.CommonDialog');  
    dialog.Filter='All Files(*.*)|*.*';  
    dialog.MaxFileSize=32767;  
    //dialog.AllowMultiSelect = true;
    dialog.DialogTitle=szPrompt;
    dialog.Flags=0x200|0x80000|0x800|0x4|0x200000  
    dialog.ShowOpen();  
    //var ret = dialog.FileTitle;
    var ret = dialog.FileName;
    dialog = void 0;
    return ret;
}  

In this logon script, we are loading a set of libraries for the WSOffice extension, a set of functions housed in an external script file, and we also have a function that will obtain specific files for uploading. This particular logon script is from an Offline implementation, but you can use logon scripts in any interface.

The logon script is typically named 'elogon.sjs'. This is the same regardless of the target language - if you name the logon script anything other than 'elogon.sjs', the file will not be read.

There is no standard group of elements that will be contained in the logon script file. However, some of the elements that are often contained in the elogon.sjs file are as follows.

'load' commands

'load' commands are used to load external files or libraries for use by the WS engine. Please see the load section for more information.

'onscreen' commands

'onscreen' commands specify a particular screen where an operation will occur. Please see the onscreen section for more information.

'set' commands

'set' commands are used to add a value to a given object in SAP. Please see the set section for more information.

You may also use other commands in logon scripts. However, keep in mind that anything in a logon script will run at logon.


Session Script (esession.sjs)

The session script file (for English this is named 'esession.sjs') is used to contain any functions or commands that need to be loaded when you launch a new session in SAP. Like the logon script file, this file is not required for a WS implementation, but it is good practice to use it if you have elements that need to be loaded or called when a new session starts. Anything contained in the session script file will be used universally in your scripts for that particular session.

Session scripts are named by prefixing a one-digit language code to the word 'session'. So for English, a session file would be named 'esession.sjs', while for Japanese, the file would be named 'jsession.sjs', a French session script would be 'fsession.sjs' and so forth.

Like the 'elogon.sjs' file, there is no specific set of elements that will always be included in this file - its contents are dependent on the needs of a particular implementation. An example esession.sjs file is shown below.

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, "");}	//Creates a string prototype function

currentUser = _user.toLowerCase().trim();
println('########## current user: ' + currentUser);

switch(currentUser) {


	case "maki": 
		{
			currentDirectory = "d1=C:\\GuiXT\\WSScripts"		//Real Demo
			break;
		}
		
	case "demo1":
		{
			currentDirectory = "d1=C:\\GuiXT\\Demo3_Scripts"	//Test1
			break;
		}

	case "demo2":
		{
			currentDirectory = "d1=C:\\GuiXT\\Scripts"			//Working folder
			break;
		}

	case "jasupport1":
		{
			currentDirectory = "d1=C:\\GuiXT\\Demo_Scripts"		//Training
			break;
		}

	case "jasupport2":
		{
			currentDirectory = "d1=C:\\GuiXT\\Demo2_Scripts"	//Excel demo
			break;
		}
		
	default:
		{
			currentDirectory = "d1=C:\\GuiXT\\WSScripts"
			break;
		}

}


In this session script, we have created a switch statement so that for each of several different users, the default script directory will be set to the correct directory for that particular user when the session starts.


Functions Script(functionsSystem.sjs)

The functions script file is used to contain any functions or commands that you wish to make available to all scripts. This makes for easier script management by placing the functions in a single location. Using a single file to contain your functions also makes the scripts more portable, and allows for less re-coding of the same processes as the functions are available to any transaction, being separate from the transaction-specific scripts. An example from a functionsSystem.sjs file is shown below.

/*
**	Open Excel file
*/
function open_excel(filename)
{
    if(g_ExcelApp == void 0)
	g_ExcelApp = new ActiveXObject('Excel.Application');
    g_ExcelBook = g_ExcelApp.Workbooks.Open(filename);
    g_ExcelApp.Visible = true;
    g_ExcelApp.ScreenUpdating = true;
}

/*
**	get first item level column number (needs to be populated in to a table)
*/
var firstItemColumn;
function get_first_item_column(activesheet){
	//find firstItemColumn
	var lastCol = 3;
	for (var nCol=2; nCol < lastCol; nCol++){
		if (activesheet.Cells(1,nCol).Value.indexOf(",") > -1){
			firstItemColumn = nCol;
			break;
		} else {
			lastCol++;
		}
	}
}


/*
**Check if Screen Control exists str = "F[Material]", str = '#[3,0]'
*/
function isControl(str) {
	return Reebok(str).isValid;
}

In this function script, we have entered several functions, thus making them more portable as previously explained and enabling you to call them from any script file, instead of replicating them in each relevant script. In this case we are performing operations related to the Excel data migration, but you can use the function script for any functions that you wish to have available to any transactions or processes.

Note: If you decide to create a function script, it is important to ensure that the script file is loaded in the logon script as previously demonstrated, otherwise the functions may not be available.