AFTER INSERT block

The AFTER INSERT block of INPUT ARRAY is executed when the creation of a new row is validated. In this block, you can for example implement SQL to insert a new row in the database table.

The AFTER INSERT block is executed afterthe AFTER FIELD block and before the AFTER ROW block.

When called in this block, the DIALOG.getCurrentRow() function returns the index of the last row.

When the user appends a new row at the end of the list, then moves UP to another row or validates the dialog, the AFTER INSERT block is only executed if at least one field was edited. If no data entry is detected, the dialog automatically removes the new appended row and thus does not trigger the AFTER INSERT block.

When executing a NEXT FIELD in the AFTER INSERT block, the dialog will keep the focus in the list and stay in the current row. Use this behavior to implement row input validation and prevent the user from leaving the list or moving to another row. However, this will not cancel the row insertion and will not invoke the BEFORE INSERT / AFTER INSERT triggers again. The only way to keep the focus in the current row after the row was inserted is to execute a NEXT FIELD in the AFTER ROW block.

In this example, the AFTER INSERT block inserts a new row in the database and cancels the operation if the SQL command fails:

INPUT ARRAY p_items FROM s_items.*
    ...
    AFTER INSERT
      WHENEVER ERROR CONTINUE
      INSERT INTO items VALUES ( p_items[DIALOG.getCurrentRow("s_items")].* )
      WHENEVER ERROR STOP
      IF SQLCA.SQLCODE<>0 THEN
         ERROR SQLERRMESSAGE
         CANCEL INSERT
      END IF