Support > Repository > Screen function > [Application] Call external command from original button
ja | en

This section explains how to execute external command by calling bat file (or sh file) from the original button prepared on the screen.

This is an example of placing a button called "Batch start" on the new registration screen.

Fig. 1 Preparing the "Batch start" button

In this example, when this button is pushed, "contents of Wagby installed folder" is outputted to the Tomcat console.

Figure 2 Example of executing button press

Prepare buttons in "Screen> Other> Java source code setting" column.

The button name is optional, but the event name is prefix "Original".In this example, the name of the event is added with Original 1 and the number 1 added.

Figure 3 Preparing the original button

A button is prepared according to the setting above, but the processing when this button is pressed is described by Java source code or script.This section explains how to write by script.

Script name

The script name is "screen type + model ID +" _ "+ event name".

The screen type is SCREENTYPE functionThe return value.However, it starts with an uppercase letter.Specifically, it is Show, Insert, Update etc.

The model ID must begin with an uppercase letter.For the customer model, it is Customer.

For the event name, use the description set in Figure 3.

I will summarize the above.In Figure 3, the script name is InsertCustomer_Original1.js.

"Check the script file name to be calledBy using the method, you can easily know.

Placement location

You can immediately check the operation by saving the script file directly over the already built application.(Pressing the button executes the script.)
In this case wagbyapp/webapps /Project identifier/ WEB - INF/script/Save to model ID folder.

Save the script file that you can check the operation in customize/webapp/WEB-INF/script/model ID folder.(The script/model ID folder is created by the developer.This file will be included in the next build process.

Basic form of script

The script created by the developer is "business logic> details of generated script file> Basic templateIt is a good idea to use the model of "

function process() {
var ExcelFunction = Java.type("jp.jasminesoft.util.ExcelFunction");
var Jfcerror = Java.type("jp.jasminesoft.jfc.error.Jfcerror");
var Jfcwarn = Java.type("jp.jasminesoft.jfc.error.Jfcwarn");
var Jfcinfo = Java.type("jp.jasminesoft.jfc.error.Jfcinfo");
var stdout = java.lang.System.out;

...ここに開発者独自のコードを記述する...

}

Script to execute external command

Use EXEC function7.10

We use the function ExcelFunction.EXEC provided by Wagby.For details of arguments etc., see "Function> EXECPlease read.

function process() {
  var ExcelFunction = Java.type("jp.jasminesoft.util.ExcelFunction");
  var Jfcerror = Java.type("jp.jasminesoft.jfc.error.Jfcerror");
  var Jfcwarn = Java.type("jp.jasminesoft.jfc.error.Jfcwarn");
  var Jfcinfo = Java.type("jp.jasminesoft.jfc.error.Jfcinfo");
  var stdout = java.lang.System.out;
 
  var result = ExcelFunction.EXEC("../..", "cmd", "/C", "dir");
  stdout.println(result);
}

When you want to specify environment variables

We use the class jp.jasminesoft.jfc.job.ProcessExecTask provided by Wagby.this is"Job to execute external commandIt is what is used in.

Methods providedDescriptionAn example
setCmd(String cmd) Describe the processing you want to execute. cmd /C \"dir C:\"
setDir(String dir) Specify the folder to execute.The default is wagbyapp/bin. C:\work
setMap(Map<String,String> map) You can pass and pass environment variables in java.util.Map.The key of Map is interpreted as environment variable name, value is interpreted as value of environment variable. (abridgement)
execute(DbActionParameter p) Execute the processing passed in setCmd.The character output by the processing to the console is the return value. (abridgement)

A sample script to execute external commands using this class is as follows.

function process() {
  var ExcelFunction = Java.type("jp.jasminesoft.util.ExcelFunction");
  var Jfcerror = Java.type("jp.jasminesoft.jfc.error.Jfcerror");
  var Jfcwarn = Java.type("jp.jasminesoft.jfc.error.Jfcwarn");
  var Jfcinfo = Java.type("jp.jasminesoft.jfc.error.Jfcinfo");
  var stdout = java.lang.System.out;
 
  var ProcessExecTaskClass = Java.type("jp.jasminesoft.jfc.job.ProcessExecTask");
  var processor = new ProcessExecTaskClass();

  processor.setCmd("cmd /C \"dir C:\"");
  processor.setDir("../..");
  var result = processor.execute(p);
  stdout.println(result);
}
  • In the setCmd method's argument, write the processing (batch file name) you want to execute.In this case, the command that returns the directory list which the Windows OS provides as standard is described.
  • In the setDir method, specify the folder at runtime.Since wagbyapp/bin is the default, you can specify the Wagby installation folder by specifying the relative path as in the above example.
  • The argument "p" of the execute method can be used implicitly in the script.Please use as it is.

To define your own button on the detail display screen and open your own screen again (same data detailed display screen) after pressing the button, write the script as follows.

Let's assume that the model is customer and the primary key item is customerid.Let's say the script file is ShowCustomer_Original1.js.

function process() {
  var ExcelFunction = Java.type("jp.jasminesoft.util.ExcelFunction");
  var Jfcerror = Java.type("jp.jasminesoft.jfc.error.Jfcerror");
  var Jfcwarn = Java.type("jp.jasminesoft.jfc.error.Jfcwarn");
  var Jfcinfo = Java.type("jp.jasminesoft.jfc.error.Jfcinfo");
  var stdout = java.lang.System.out;

  ...(開発者が行う処理)...

  var id = p.request.getParameter("customerid");
  return "redirect:/showCustomer.do?customerid="+id;
}

When returning to the details screen of yourself, specify the primary key.