Professional Documents
Culture Documents
Personas Java Script
Personas Java Script
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Welcome to the new version of SAP Community Wiki: Learn What's New? and what has
changed.
Community Wiki
Spaces
Quick Search
Help
Log in
SAP Imagineering
Pages
1.
2.
3.
Product Support
Product Updates
Fundamentals
SAP Fiori UX
Mobile Topics
Editor
Scripting
Administration
Integration
Purpose
This article shows how a Javascript library can be included within scripts so that functions from
the library can be reused across scripts within a flavor or scripts across flavors. This feature helps
remove code duplication in scripts and improves maintainability.
Overview
In order to include a Javascript library to be used in scripts, the Javascript file must be uploaded
as a resource file using the SAP Screen Personas administration transaction and the uploaded
resource ID can then be used as a parameter of the session.utils.include API. These steps are
explained in detail in the following sections. There is also a section that mentions a few caveats
on how the Javascript libraries need to be structured to work correctly in SAP GUI for Windows
and SAP GUI for Java.
I will use a Javascript file with the following contents and will refer to the file name as
'TableControlUtilities.js' in this section.
TableControlUtilities.js
1 /**
2 * Returns an array of rows containing information from the table control.
* @param {string} sTableControlId - The ID of the table control.
3 * @returns {Array[Object]} The contents array.
4 */
5 copyTableContents = function(sTableControlId) {
6 // Fetch the table and its columns
var oTableControl = session.findById(sTableControlId),
7 aColumns = oTableControl.columns,
8 aContents = [],
9 nTopRow,
1 oRow,
0 sColumnName,
nRowIndex,
1 i;
1 if (oTableControl.rowCount > 0) {
1 //Set the visible row to 0
2 oTableControl.firstVisibleRow = 0;
1 //Get the Max visible row number
nTopRow = oTableControl.visibleRowCount - 1;
3 //Loop through all the rows
1 for (nRowIndex = 0; nRowIndex < oTableControl.rowCount; nRowIndex++)
4 {
1 oRow = {};
if (nRowIndex > nTopRow) {
5 // Set the first visible row to the next set of rows. If the
1 next set goes beyond the maximum rows,
6 // adjust it so that the set's last row is the table's last
row.
1
if (nTopRow + oTableControl.visibleRowCount >
7 oTableControl.rowCount) {
1 oTableControl.firstVisibleRow = oTableControl.rowCount -
8 oTableControl.visibleRowCount;
1 } else {
oTableControl.firstVisibleRow = nTopRow + 1;
9 }
2 nTopRow += oTableControl.visibleRowCount;
0 }
2 // Populate the row information.
1 for (i = 0; i < aColumns.length; i++) {
sColumnName = aColumns.elementAt(i).name;
2 oRow[sColumnName] = oTableControl.getCellValue(nRowIndex,
2 sColumnName);
2 }
3 // Break after the first blank row - the values usually contain
all underscores like "____" for a 4 character column.
2 if (!oRow[aColumns.elementAt(0).name].replace(/_/g, "")) {
4 break;
2 }
5 aContents.push(oRow);
2 }
}
6 return aContents;
2 };
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
The uploaded Javascript library can be used in any script of any flavor using the
session.util.include API. This function accepts two parameters:
alwaysExecute: this accepts a Boolean value - if set to 'true', then the Javascript file is always
executed when the include is called; if set to 'false', the Javascript file is only executed once
when the include is called for the very first time in a session.
Here's an example of how the 'TableControlUtilities.js' library can be used to copy the contents
of a table control.
1. Go to transaction GUIT.
2. In the OK Code field, input 1000 and hit
enter key. This will open the table control
test screen.
3. Create a new flavor or open an existing
flavor and open the script editor.
4. Create a new script and input the following
script contents:
Script to Copy Contents of the GUIT -
1000 Table Control
Usage in SAP GUI for Windows and SAP GUI for Java
The session.utils.include API works as described in previous sections in SAP GUI for HTML.
There are a couple of caveats for using the API in SAP GUI for Windows and SAP GUI for
Java:
1var tableControlLibrary = {
2 copyTableContents: function(sTableControlId) {
// Implementation...
3 },
4 exportToSpreadsheet: function(sTableControlId) {
5 // Implementation...
6 }
};
7return tableControlLibrary;
8
9
Related Content
Privacy
Terms of Use
Legal Disclosure
Copyright
Trademark
Cookie Preferences