Table, Duplicate
Table, Duplicate
Duplicates Table-type data. All cell values stored in Table-type data A is copied over to Table-type data B. If the table column definitions are different, an error may occur.
Configs
  • A: Select TABLE DATA *
  • B: Select TABLE DATA (update)
  • B2: Select TABLE DATA (append)
Script (click to open)
// GraalJS Script (engine type: 2)
//
// Notes:
// Copies text information of all cell values.
// Copies in the display order of the column. (Does not refer to column ID/field name)
// If the number of columns decreases, the right columns will not be copied.
// If the number of columns increases, blank strings will be completed.
// To re-order columns, consider Table-TsvString-TsvEdit-Table.
// Auto-calculated columns are reevaluated. (Not always the same value)
// Use the standard function for duplication of string, numeric, date, etc.
// - Automated Step (BPMN Icons): "Service Task (Data Assignment)"
// - M227: Auto Executing Data Binding, Arithmetic Operations
// To add data without erasing already stored cell data, use B2.
//
// Notes (ja):
// 全てのセル値の文字情報をコピーします。
// カラムの表示順にコピーします。(カラムID/フィールド名に関わらない)
// カラム列数が少なくなる場合は、右列部がカットされます。
// カラム列数が増える場合は、空白文字列で補完されます。
// 列の入れ換えは、Table→TSV文字列→TSV加工→Table等を検討してください。
// 自動計算カラムは、再評価されます。(必ずしも同じ値になりません)
// 文字列型・数値型・日付型などのデータ複製には、標準機能をご活用ください。
// - 自動処理工程(BPMNアイコン): [サービスタスク(データ設定)]
// - M227: 業務データの結合や四則演算が自動実行されるように設定する
// 既に格納されているセルデータを消さずに追記したい場合は、B2をご利用ください。


//////// START "main()" ////////////////////////////////////////////////////////////////
main();
function main(){

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + ""; // required
const dataIdB = configs.get( "conf_DataIdB" ) + ""; // not required
const dataIdB2 = configs.get( "conf_DataIdB2" ) + ""; // not required
// 'java.lang.String' to javascript primitive 'string'

const numColsA = engine.findDataDefinitionByNumber( dataIdA ).getSubDataDefinitions().size() - 0; // java.util.List<com.questetra.bpms.core.event.scripttask.SubDataDefinitionView>#size()
engine.log( " AutomatedTask TableConfig:" +
            " #of {A}-Columns Definition: " + numColsA );

let outputTable1ProcessDataDefinitionView = null;
let outputTable1DataDefinition = null;
let outputTable1 = null;
let numColsB = 0;
if( dataIdB !== "" ){
  outputTable1ProcessDataDefinitionView = engine.findDataDefinitionByNumber( dataIdB ); // com.questetra.bpms.core.event.scripttask.ProcessDataDefinitionView
  outputTable1DataDefinition = outputTable1ProcessDataDefinitionView.getSubDataDefinitions(); // java.util.List<com.questetra.bpms.core.event.scripttask.SubDataDefinitionView>
  outputTable1 = outputTable1ProcessDataDefinitionView.createListArray(); // com.questetra.bpms.core.event.scripttask.ScriptListArray
  numColsB = outputTable1DataDefinition.size() - 0;
  engine.log( " AutomatedTask TableConfig:" +
              " #of {B}-Columns Definition: " + numColsB );
}

let outputTable2ProcessDataDefinitionView = null;
let outputTable2DataDefinition = null;
let outputTable2 = null;
let numColsB2 = 0;
if( dataIdB2 !== "" ){
  outputTable2ProcessDataDefinitionView = engine.findDataDefinitionByNumber( dataIdB2 ); // com.questetra.bpms.core.event.scripttask.ProcessDataDefinitionView
  outputTable2DataDefinition = outputTable2ProcessDataDefinitionView.getSubDataDefinitions(); // java.util.List<com.questetra.bpms.core.event.scripttask.SubDataDefinitionView>
  outputTable2 = engine.findDataByNumber( dataIdB2 ); // com.questetra.bpms.core.event.scripttask.ScriptListArray
  if( outputTable2 === null ){
    // Table with zero rows.
    outputTable2 = outputTable2ProcessDataDefinitionView.createListArray(); // com.questetra.bpms.core.event.scripttask.ScriptListArray
  }
  numColsB2 = outputTable2DataDefinition.size() - 0;
  engine.log( " AutomatedTask TableConfig:" +
              " #of {B2}-Columns Definition: " + numColsB2 );
}


//// == Data Retrieving / ワークフローデータの参照 ==
const inputTable = engine.findDataByNumber( dataIdA );
// com.questetra.bpms.core.event.scripttask.ScriptListArray (BPMS Table)
// https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300
if( inputTable === null ){
  throw new Error( "\n AutomatedTask UnexpectedTableError:" +
                   " Table {A} is empty \n" );
}


//// == Calculating / 演算 ==
if( dataIdB !== "" ){
  for( let i = 0; i < inputTable.size() - 0; i++ ){
    let tmpRow = outputTable1.addRow(); // com.questetra.bpms.core.event.scripttask.ScriptListArray.ScriptListRow
    if( numColsA < numColsB ){
      for( let j = 0; j < numColsA; j++ ){
        tmpRow.setCol( j, inputTable.getRow(i).getCol(j) );
      }
      for( let k = numColsA; k < numColsB; k++ ){
        tmpRow.setCol( k, "" ); // Fill with empty characters
      }
    }
    if( numColsA >= numColsB ){
      for( let j = 0; j < numColsB; j++ ){
        tmpRow.setCol( j, inputTable.getRow(i).getCol(j) );
      }
    }
    engine.log( " AutomatedTask:" +
                " Add B[" + i + "]" );
  }
}

if( dataIdB2 !== "" ){
  let numOriginLines = outputTable2.size() - 0;
  engine.log( " AutomatedTask:" +
              " #of {B2}-Rows: " + numOriginLines );

  for( let i = 0; i < inputTable.size() - 0; i++ ){
    let tmpRow = outputTable2.addRow(); // com.questetra.bpms.core.event.scripttask.ScriptListArray.ScriptListRow
    if( numColsA < numColsB2 ){
      for( let j = 0; j < numColsA; j++ ){
        tmpRow.setCol( j, inputTable.getRow(i).getCol(j) );
      }
      for( let k = numColsA; k < numColsB2; k++ ){
        tmpRow.setCol( k, "" ); // Fill with empty characters
      }
    }
    if( numColsA >= numColsB2 ){
      for( let j = 0; j < numColsB2; j++ ){
        tmpRow.setCol( j, inputTable.getRow(i).getCol(j) );
      }
    }
    engine.log( " AutomatedTask:" +
                " Add B2[" + (numOriginLines + i) + "]" );
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
if( dataIdB !== "" ){
  engine.setDataByNumber( dataIdB, outputTable1 );
}
if( dataIdB2 !== "" ){
  engine.setDataByNumber( dataIdB2, outputTable2 );
}


} //////// END "main()" ////////////////////////////////////////////////////////////////

Download

2021-08-19 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/table-duplicate-2021/
The Add-on import feature is available with Professional edition.

Notes

  1. Copies text information of all cell values.
  2. Copies the columns in the order in which they appear (regardless of the column ID/field name).
  3. If the number of columns decreases, the right columns will not be copied.
  4. If the number of columns increases, the extra columns will be completed with blank strings.
  5. To re-order columns, consider Table-TsvString-TsvEdit-Table.
  6. Auto-calculated columns are re-evaluated. (They will not necessarily have the same value.)
  7. Use the standard functions for duplication of string, numeric, date, etc.
    1. Automated Step (BPMN Icons): “Service Task (Data Assignment)”
    2. M227: Auto Executing Data Binding, Arithmetic Operations
  8. To add data without erasing already stored cell data, use B2.

Capture

Duplicates Table-type data. All cell value stored in Table-type data A is copied over Table-type data B. If the table column definitions are different, an error may occur.

See also

1 thought on “Table, Duplicate”

  1. Pingback: Table, Duplicate – Questetra Support

Comments are closed.

%d bloggers like this: