Starting Point

The shipped aXes demonstration screen named XHRRPGTRN_Select is used.

The subfile selection column field is named Sel, and the employee number, Surname, Given Name and Date of Birth columns are named Employee, Surname and Given_Name and Date_of_Birth respectively:

Image

Result

A copy to clipboard push button has been added. When clicked all the subfile entries on the current screen are copied to the clipboard. The copy is achieved by invoking a generic function defined in the USERENV object:

Image

Steps

  1. This generic function was added to the USERENV object (this code is a generic version of the code using in the preceding subfile and clipboard example):

  2. sendSubfiletoClipBoard : function(oP)

    {

    var iSFLIndex = 0;

    var iLimit = oP.sendFields.length;

    var sClipData = "";

    var sTab = "\t";

    var sNL = "\n";

    var oiterField = null;

    iSFLIndex = 1;

    oiterField = oP.ENV.FIELDS(oP.iterField,iSFLIndex);

    while (oiterField != null)

    {

    for (var i = 0; i < iLimit; i++)

    {

    var osendField = oP.ENV.FIELDS(oP.sendFields[i],iSFLIndex);

    if (osendField != null) sClipData += osendField.getValue() + sTab;

    else sClipData += oP.notFound + sTab;

    }

    sClipData += sNL;

    iSFLIndex += 1;

    oiterField = oP.ENV.FIELDS(oP.iterField,iSFLIndex);

    }

    window.clipboardData.clearData();

    if (sClipData != "") window.clipboardData.setData("Text",sClipData);

    }, /* <= Note the comma */

  3. A new aXes developer browser session was started to ensure that the updated USERENV code is loaded.
  4. A new element was added to the XHRRPGTRN_Select screen as a push button.
  5. These properties were then set in the push button eXtension:
  6. caption (simple text):

    Copy Subfile to Clipboard

    onClick (script)

    var oP = { ENV : ENV,

    iterField : "Employee",

    notFound : "Not found",

    sendFields: ["Employee","Surname","Given_Name","Date_of_Birth"] };

    USERENV.sendSubfiletoClipBoard(oP);

Observations

The USERENV function sendSubfiletoClipBoard receives an object as a parameter.

The properties within the object parameter are:

  • ENV: a reference to the calling scripts ENV execution environment. This allows the generic code to access the callers standard functions, etc.
  • iterField: The name of the subfile fields to use to iterate the subfile.
  • notFound: The text to be output to the clipboard for a field not found in the subfile.
  • sendFields: An array of the names of the subfile fields to be copied to the clipboard.

Using a generic routine like this in USERENV means that it is easier to add a "Copy to Clipboard" button to lots of screens and avoid repeating JavaScript code.


Administrators

Legal Mentions

aXes is brought to you by:

LANSA

Serving the IBM i community for 30 years.