Support > Repository > Business logic > Sample code
ja | en

I will show sample code that I can use for work.

Requirement

Model model1 has repeating container cont.

Model1 has "scheduled date (yoteibi)" "title" item. Also, there are "next scheduled date (jikaiyoteibi)" and "title (ctitle)" in repeat container cont of model 1.

item name Item ID Type
scheduled date yoteibi date
title title String
Minutes cont Repeat container
No cont/cid Repeating Container ID
Next scheduled date cont/jikaiyoteibi date
Next title cont/ctitle String
"Title" and "Next title" are assumed to be the same type.Although it is a character string on the above, it can also be a model reference method.(There is a model named Title Master, it will be a selection formula, etc.)

If a date is included in the "next scheduled date" in the repeating container field, register the new object * which set the value in the container repeatedly in the scheduled date and title.

(That is, if one model 1 data is registered, if there is one repeating container, another data is also registered at the same time.)

Written place of script

After model 1's new registration process succeeds, it is assumed.Specifically, it is described in "Controller> Register (Screen)> Execute Registration (Timing)".

var Model1Class = Java.type("jp.jasminesoft.wagby.model.model1.Model1");
var service = p.appctx.getBean("Model1EntityService");
var helper = p.appctx.getBean("Model1Helper");
var cont = model1.cont;
if (cont != null) {
    for (var i=0; i<cont.length; i++) {
        if (cont[i].jikaiyoteibi != null) {
            var n_model1 = new Model1Class();/*オブジェクト作成*/
            helper.initialize(n_model1, p);/*オブジェクト初期化*/
            n_model1.yoteibi = cont[i].jikaiyoteibi;
            n_model1.title = cont[i].ctitle;
            /*stdout.println(n_model1);*/
            service.insert(n_model1);
        }
    }
}
  • The 1st, 2nd and 3rd lines are codes for using store model Model 1, service class (of Model 1), helper class (of Model 1), respectively.
  • In line 7, it is judging whether or not the date is included in the "next scheduled date" in the repeating container item.
  • In line 8 we are creating a new object.
  • The object is being initialized at line 9.[More ...]
  • In the 10th and 11th rows, the value of the repeating container is set.
  • In line 13, new objects are registered in the database.In this example the primary key uses ordering.(Because it is an automatic number assignment, a primary key is assigned in the service.insert method.)

ExcelFunction.EXEC can be used to execute external commands.

var ret = ExcelFunction.EXEC("../..", "cmd", "/C", "dir");
stdout.println(ret);

An example of executing an external command from the original button is prepared."Screen function> [Application] Call external command from original buttonPlease read.

For details of the EXEC function, see "Function> Other> EXECPlease read.