Support > Repository > Business logic > Update after list form output
ja | en

After executing the form output, I will introduce the script to be called. R7.7

You can write the processing at the time of pressing "Post document output" or "Post document output (list)" button as script code.

Figure 1 Script description field

The script that sets the value to the "form output date" item of the model which is the target of the form output is as follows.

var entityService = p.appctx.getBean("CustomerEntityService");
try {
    var n_customer = entityService.findById(customer.customerid, true);
    n_customer.printdatetime = ExcelFunction.NOW();
    entityService.update(n_customer);
    stdout.println(n_customer);
} catch (e) {
    stdout.println(e);
}

This script can be applied to both detailed screen and list screen.In the case of the list screen, it is applied to all the target data of the form output.

  • We use the CustomerEntityService object to perform update processing.For details of the service object, see "Service/Dao class, using SQLPlease read.
  • Use the service object's findById method to get the latest state from the database.At this time, as the second argument true By setting, locking is applied.
  • Set the current date and time in the date/time item (here, the customer model's printdatetime item).ExcelFunction..NOW () is a function provided by Wagby.Returns the current date and time.
  • Assuming what happened when updating failed, we surrounded the whole with try-catch.For example, when a lock fails, the catch clause is processed.

important point

After changing the value, the data displayed on the detail screen (or list screen) shows the value of the printdatetime item before updating.It is not after updating.This is because the value is updated when the form output succeeded, but the screen display data is prepared before that.

If you redraw the screen, you can check the updated value.

Prepare an integer type item printcount.The next script increases the value by 1 each time the form output is done.

var entityService = p.appctx.getBean("CustomerEntityService");
try {
    var n_customer = entityService.findById(customer.customerid, true);
    n_customer.printcount = n_customer.printcount + 1;
    entityService.update(n_customer);
} catch (e) {
    stdout.println(e);
}

This script can be applied to both detailed screen and list screen.In the case of the list screen, it is applied to all the target data of the form output.

  • We use the CustomerEntityService object to perform update processing.For details of the service object, see "Service/Dao class, using SQLPlease read.
  • Use the service object's findById method to get the latest state from the database.At this time, as the second argument true By setting, locking is applied.
  • Set a value added to the current value of an integer type item (here, the customer model's printcount item).Please set the initial value of item printcount to 0.(If you do not set this initial value, the default initial value is '-1'.Therefore, the first execution result is 0 instead of 1.)
  • Assuming what happened when updating failed, we surrounded the whole with try-catch.For example, when a lock fails, the catch clause is processed.

important point

After changing the value, the data displayed on the detail screen (or list screen) shows the value of the printdatetime item before updating.It is not after updating.This is because the value is updated when the form output succeeded, but the screen display data is prepared before that.

If you redraw the screen, you can check the updated value.

If you have prepared multiple form patterns, you can branch the process depending on which button was pressed.

By pushing the button, the value is set in p.action.Use this value to perform the following conditional branch.

if (p.action == "PrintCustomer_showListCustomer") {
...
}

Points of development

First in the script

stdout.println(p.action);

For example, if you press the button, you should check what value is stored in p.action.

  • This script also applies to multiple data selected in the check box in the list form output.
  • R7.8