Terminal Macro Engine

Green Screens Web Terminal Macro engine is a screen automation module which provide automatic screen field data entry and terminal screen processing by executing JSON based definitions.

Macros itself can be defined as a single JSON object (macro running definition) or as an array of macro definitions to be executed sequentially.

While starting macro executor, callback function will be invoked every time when macro execution response is received (new screen is received).

Today, we will present a simple example which shows basis as a foundation for more advanced features like automatic screen ETL or automatic screen data extraction to office documents.

Before we continue into details, let us show you a short presentation video showing automatic WRKACTJOB subfile scrolling.

...and for the purpose of this blog another video showing spool files automatic removal.

First, we need to define macro or multiple macros to be executed. In our case, this simple example shows macro definition with automatic sign on, accessing WRKACTJOB and scrolling through subfile data.

var macros = [
    {
      "cmd": "ENTER",
      "detect": {"r":0, "c":35, "t": "Sign On"},
      "fields": [[1,"QSECOFR"], [6,52,"QSECOFR"]]
    },
    {
      "cmd": "ENTER",
      "fields": [[1,"WRKACTJOB"]],
      "detect": "main",
      "query" : {
        "main" : "main1 || main2"
      },
      "segments" : {
       "main1" :  {"r":0, "c":32, "t":"OS/400 Main Menu"},
       "main2" : {"r":0, "c":32, "t":"IBM i Main Menu "}
      }
    },
    {
      "cmd": "PGDOWN",
      "detect": {"r":0, "c":29, "t":"Work with Active Jobs"},
      "startTrigger": {"r":18, "c":72, "t":"More..."},
      "stopTrigger": {"r":18, "c":73, "t":"Bottom"},
      "strict": true
    }
];

Properties like detect and triggers contains screen coordinates and expected value. For example [0,35,'Sign On'] means: at row 0 and col 35 'Sign On' value should exist.

NOTE: Fields can be defined as a field ID starting from 1 or as a screen position by row/col values.

Next step is to run macro definition through web terminal macro engine.

// callback function triggered on every macro execution response
function callback(e,signal,cfg,data) {

  //log processing steps
  console.log(JSON.stringify(signal));

  //process new screen data
  if (signal.signal === 1) {
    var obj = Tn5250.Parser.screenExtract(data, cfg); 
    console.log(JSON.stringify(obj));
  }

  //macro processing has ended
  if (signal.signal === 0) {
     console.log('macro is finished');
  }

}

//start macro execution
var sts = Tn5250.Macro.execute(macros, callback);
console.log(sts);

When combining macro with other features like automatic screen triggers, macros need to be accessible for general and programmable use. In such case, macro definitions can be saved inside configuration directory at the server side [user]/io.greenscreens/etl and later retrieved with D-API as shown in following example...

io.greenscreens.ETLController.getDefinition('macro.json', function(res,data,sts) {
    console.log(JSON.stringify(data));
});

To execute macro from server side use this snippet.

io.greenscreens.ETLController.getDefinition('macro.json', function(res,data,sts) {
    Tn5250.Macro.execute(macros, function(e,signal,cfg,data) {
       console.log(signal.signal);
    });
});