Support > Repository > Business logic > Mass update

We describe the body of "bulk update" processing prepared on the list display screen with a script.

You can write the processing at the time of pressing "batch update" button as script code.

Figure 1 Script description field

When you modify the script in Designer, it is immediately reflected in the application on the development machine.You can check the fix without building process.

In the script, "object" corresponding to the model name can be used.

Set "1" to the radio_flag field of all customer models checked on the list display screen.

customer.radioFlag = 1;/*選択された複数のcustomerに適用される。*/

It treats the checkbox type keyperson item as a toggle switch.The checked value is canceled and the released value is checked.Since it is a check box, it is treated as an array.

var flag = customer.keyperson;/*チェックボックスによるON/OFF項目*/
if (flag == null || flag[0] == 0) {
    customer.keyperson = 1; /* OFF から ON へ */
} else if (flag != null && flag[0] == 1) {
    customer.keyperson = 0; /* ON から OFF へ */

When preparing multiple batch updating buttons, please judge by the value of p.action in the script. Specific code examples are shown below.

if (p.action == "UpdateAll") {
    /* ボタン1 の処理 */
} else if (p.action == "UpdateAll2") {
    /* ボタン2 の処理 */
} else ...

The first button is determined by UpdateAll.The second and subsequent buttons are UpdateAll 2, UpdateAll 3, ....

Before this is called, the bulk update script is performing automatic calculation processing and reference link resolution processing for that model.However, recalculation using the updated value or reference linkage is not performed.

If you call the calculation process again using the value modified by the mass update script, write it as follows.

return "calc";

This is a rule only for bulk update scripts.If the reference linkage item is included here, the calculation is performed after resolution of the reference linkage.

To further perform the reference linkage process using the calculation result, write as follows.

return "calc,resolv";

If you write calc, resolv with a comma delimited list, after automatic calculation, resolve the reference linkage and save the value in the database.

In the case of a complicated model configuration in which the reference synchronization is resolved using the result of automatic calculation and then automatic calculation using that value is performed and the reference linking is again performed using the result, It can also be described as follows.return "calc,resolv,calc,resolv";

You can specify the screen to transition after batch update processing.For example, to change to the main menu, write the following script at the timing of "Controller> List> Screen transition".

Figure 2 Controlling screen transitions
if (p.action == "UpdateAll") {
  return "forward:/";
It determines which button was pressed by the value of p.action.Be sure to give this condition.

Normally, after completion of batch update processing, "Update of xx number of yy data was done."Message will be displayed.We customize this so that we display only the number of data actually updated according to the conditions.Here we apply the screen transition script.

Figure 3 Standard message

Count processing

Prepare a variable that counts the number of processes in the "helper> batch update" script.


var counter = p.request.getAttribute("myapp.counter");
if (counter == null) {
    counter = 1;
    p.request.setAttribute("myapp.counter", counter);
} else {
    counter = counter + 1;

P.request is a special object that can be used as a container that can hold variables you want to keep during this mass update process.In this example the name is myapp.counter.Although you can use arbitrary names, please use names that do not duplicate other names used by Wagby and manage them easily.(Try devising such as giving a prefix meaning application as in the example above.)

In the above code, 1 is set for the first time.The counter variable is increased for the second time onwards.A developer can implement a rule such as not incrementing the counter if the value is not updated depending on the condition, for example.

Display message

Display messages in "Controller> List> Screen Transition".

if (p.action == "UpdateAll") {
  var counter = p.request.getAttribute("myapp.counter");
  if (counter != null) {
    var info = new Jfcinfo();
    p.errors.clearJfcinfo();/* 標準のメッセージを削除する */

P.request holds the value of myapp.counter until this mass update process is over.(When the batch updating process is completed, this value is automatically deleted from p.request.)

Jfcinfo is a message displayed on success.For details, please read "Error message> INFO".

Standard messages can be deleted by calling p.errors.clearJfcinfo ().This forcibly replaces the message and displays it.

Combined use with workflow

The batch update button is not displayed in the model where the workflow is defined.

When using workflow, it is specified that only the person who holds the flow (processing pending) can update the data. It is necessary to judge whether the pending data is included in the data displayed in the list in the display of the batch update button, but this control is not currently performed and it is not displayed.

As an alternative, there is a method of creating a submodel in which the workflow setting is invalidated and collectively updating it on the submodel side. However, please be aware that this method will update the data ignoring the rule "Only data can be updated by processing penditor".Therefore, please do not refrain from updating important items used for judgment of approval/decision, or take care not to update approved data.