Support > Repository > Business logic > Details of generated script file
ja | en

The script entered in Designer is generated as a file.

The code written by the developer is embedded inside the following template code.The code is contained in the function named process.

ExcelFunction, Jfcerror, Jfcwarn, Jfcinfo, JFCUtils, HolidayManager, stdout are described in "Available Variables" below.
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 JFCUtils = Java.type("jp.jasminesoft.jfc.JFCUtils");
var HolidayManager = Java.type("jp.jasminesoft.util.HolidayManager");
var stdout = java.lang.System.out;

...ここに開発者独自のコードが埋め込まれる...

}
Java.type is a special notation.By writing Java.type (class name in FQCN format), you can prepare a variable representing Java class.With this variable you can now create an object with the new operator.

Generated files

The script entered in Designer is overwritten and saved in the script file wagbyapp/webapp/$ (APPNAME)/WEB - INF/script/model ID/script file.

So you can check the behavior of the running application without rebuilding.

The file of the production machine is not changed.Only the wagbyapp folder on the same development machine will be changed.If you want to reflect on the production machine please copy the above file manually, or build again, replace the entire wagbyapp folder.

Do not use basic templates

You can choose not to use the basic template.For example, when preparing your own function.

In this case, please be sure to start the code you develop with function process ().If the beginning of the code starts with this description, we decide not to use the basic template.

For example, it is written 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 JFCUtils = Java.type("jp.jasminesoft.jfc.JFCUtils");
var HolidayManager = Java.type("jp.jasminesoft.util.HolidayManager");
var stdout = java.lang.System.out;

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

}

function foo() {...独自の関数を記述する...}
function bar() {...独自の関数を記述する...}

You can not call the defined function (from a script saved in another file).

Detailed rules on the script are as follows.

  • [Basic template] "function process () {" is added to the beginning of script code created by the developer."}" Is added at the end.Wagby always calls this process function.
  • However, developers can explicitly write the process function declaration "function process () {" directly.In this case, declaration of some variables is also omitted, so please redefine them yourself.
  • When you change the script in Designer, the script file wagbyapp/webapp/$ (APPNAME)/WEB-INF/script/model ID/script file .js in the wagbyapp folder on the same development machine is overwritten.Therefore, you can check the behavior of the running application without building it.(Caution: The file of the production machine is not changed.Only the wagbyapp folder on the same development machine will be changed.)

Relationship with customize folder

Editing the script in the setting field provided in Designer overwrites the edited content.However, when you do the build process, it overwrites the script below customize.That is,The file in the customize folder takes precedence.

You can use the standard class provided by Java in the script.They do not need to be redeclared in Java.type.Please use the class name including the package name.

var list = new java.util.ArrayList();
list.add("Apple");
list.add("Orange");
list.add("Banana");
stdout.println(list);

It summarizes the variables available in the script.

nameRepresentation in scriptAn exampleDescription
Store model Model name customer Objects stored in the database
Presentation model Model name _ p customer_p Value entered from web form.
All string types.
Condition model Model name _ c customer_c An object that stores search conditions.
List model Model name _ l customer_l Object containing values ​​to be listed
Error message errorManager errorManager (Error messageCommentary on)
SCREENTYPE if (SCREENTYPE == "copy") {...} SCREENTYPE functionSame as.[An example]
DbActionParameter p p There is usage such as being able to reference ApplicationContext of (Spring) with p.appctx.
ExcelFunction class (*) var s = ExcelFunction.FIND(...); (Use of Wagby functionCommentary on)
Jfcerror class (*) var error = new Jfcerror; (Error messageCommentary on)
Jfcwarn class (*) var warn = new Jfcwarn; (Error messageCommentary on)
Jfcinfo class (*) var info = new Jfcinfo; (Error messageCommentary on)
JFCUtil class (*) var s = JFCUtils.Message(p, "M0001") (Wagby functionCommentary on)
HolidayManager class (*) var d = HolidayManager.getInstance().getEigyoDayAsSQLDate(model1.item1, 7) (Wagby functionCommentary on)
stdout (*) java.lang.System.out stdout.println(...); Only when using Java 8.
ExcelFunction, Jfcerror, Jfcwarn, Jfcinfo, JFCUtils, HolidayManager, stdout are declared in the basic template.(JFCUtils, HolidayManager has been included in the basic template from Wagby after R7.11.2.)
Objects other than the store model may not exist.For example, if it is not a search screen operation, the condition model is not included.
Depending on the situation, it may not be possible to acquire a store model.For example, in the case of deletion processing, the store model has disappeared.
Transaction script, You can handle multiple store models specified within the scope of a transaction.
Transaction script, You can also treat repeated containers that are subject to transactions as objects.

Developers can prepare WEB-INF/script/myfunction.js. When this file exists, its contents are included in the script.

Exactly, the scriptlaterThe code of myfunction.js is copied.

Application example

In the script, it is written as follows.

stdout.println(foo(1,2));

The developer prepares myfunction.js and defines the function foo.

Function foo (a 1, a 2) {return a 1 + a 2;

When you run the script, 3.0 will be displayed on the console.

Save the myfunction.js in the customize/webapp/WEB-INF/script folder.(In the state immediately after installation, there is no script folder in the WEB - INF folder, so please also create this.It will be reflected from the next build.

The function preprocess can be prepared at the next timing of helper.RespectivelyBeforeIt is called.

Execution timingfile name
Registration Model IDHelper_beforeInsert.js
Registration (creation of initial data) Model IDHelper_initialize.js
update Model IDHelper_beforeUpdate.js
Detailed screen display Model IDHelper_beforeShow.js

The developer should modify the above file created in the WEB-INF/script/<model ID> folder directly with a text editor and prepare the function preprocess.

function preprocess() {
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;

...ここに開発者独自のコードが埋め込まれる...

}
Editing in WagbyDesigner is reflected in the function process.After creating the function preprocess, if you edit it with WagbyDesigner, the script file will be overwritten.At this time preprocess will be erased, please be careful.