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 and Given Name columns are named Employee, Surname and Given_Name 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:

Image

Steps

  1. A new element was added to the screen as a push button.
  2. These properties were then set in the push button eXtension:
  3. caption (simple text):

    Copy Subfile to Clipboard

    onClick (script)

    var sClipData = "";

    var sTab = "\t";

    var iSFLIndex = 1;

    var oEmployee = FIELDS("Employee",iSFLIndex);

    while (oEmployee != null)

    {

    var oSurname = FIELDS("Surname",iSFLIndex);

    var oGivenName = FIELDS("Given_Name",iSFLIndex);

    sClipData += oEmployee.getValue() + sTab;

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

    else sClipData += "UNKNOWN" + sTab;

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

    else sClipData += "UNKNOWN" + sTab;

    sClipData += "\n";

    iSFLIndex += 1;

    oEmployee = FIELDS("Employee",iSFLIndex);

    }

    window.clipboardData.clearData();

    window.clipboardData.setData("Text",sClipData);

    Observations

    The employee number field was chosen to drive the subfile iteration loop because it exists for every subfile entry.

    The subfile iteration loop is structured like this:

    var iSFLIndex = 1;

    var oEmployee = FIELDS("Employee",iSFLIndex);

    while (oEmployee != null)

    {

    iSFLIndex += 1;

    oEmployee = FIELDS("Employee",iSFLIndex);

    }

    The loop starts at entry one and proceeds until an employee number cannot be found in the subfile.

    When iterating a subfile the possibility exists that blank outfield entry will not actually exist on the 5250 display. That is why the logic

    var oSurname = FIELDS("Surname",iSFLIndex);

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

    else sClipData += "UNKNOWN" + sTab;

    is used. It caters for the fact that an employee's surname may be blank and therefore the entry does not exist in the subfile.

    The clipboard data is tab delimited so it can be pasted as columns to, for example, MS-Excel.

    You would probably not code logic like this in a real application. It would be better to create a generic subfile clipboard function in your USERENV object and simply call it from the onClick routine.