コード例 #1
0
  /**
   * ************************************************************************ Save Multiple records
   * - Clone a record and assign new values to each clone for a specific column.
   *
   * @param ctx context
   * @param tableName Table Name
   * @param columnName Column for which value need to be changed
   * @param recordId Record to clone
   * @param values Values to be assigned to clones for the specified column
   * @param trxName Transaction
   * @throws Exception If error is occured when loading the PO or saving clones
   * @author ashley
   */
  protected void saveMultipleRecords(
      Properties ctx,
      String tableName,
      String columnName,
      int recordId,
      Integer[] values,
      String trxName)
      throws Exception {
    if (values == null) {
      return;
    }

    int oldRow = gridTab.getCurrentRow();
    GridField lineField = gridTab.getField("Line");

    for (int i = 0; i < values.length; i++) {
      if (!gridTab.dataNew(true)) {
        throw new IllegalStateException("Could not clone tab");
      }

      gridTab.setValue(columnName, values[i]);

      if (lineField != null) {
        gridTab.setValue(lineField, 0);
      }

      if (!gridTab.dataSave(false)) {
        throw new IllegalStateException("Could not update tab");
      }

      gridTab.setCurrentRow(oldRow);
    }
  }