Table, Duplicate

Table, Duplicate
Table, Duplicate

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.

2020-02-25 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/table-duplicate/

Configs
  • A: Select TABLE DATA *
  • B: Select TABLE DATA (update)
  • B2: Select TABLE DATA (append)
Script
// Notes:
// Copies text information of all cell values.
// Copies in the display order of the column. (Does not refer to column ID)
// 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'

let numColsA  = 0;
numColsA  = engine.findDataDefinitionByNumber( dataIdA )
                  .getSubDataDefinitions().size() - 0;
// com.questetra.bpms.core.event.scripttask.ProcessDataDefinitionView
engine.log( " AutomatedTask TableConfig:" +
            " #of {A}-Columns Definition: " + numColsA );
let numColsB  = 0;
if( dataIdB !== "" ){
  numColsB  = engine.findDataDefinitionByNumber( dataIdB )
                    .getSubDataDefinitions().size() - 0;
  engine.log( " AutomatedTask TableConfig:" +
              " #of {B}-Columns Definition: " + numColsB );
}
let numColsB2  = 0;
if( dataIdB2 !== "" ){
  numColsB2 = engine.findDataDefinitionByNumber( dataIdB2 )
                    .getSubDataDefinitions().size() - 0;
  engine.log( " AutomatedTask TableConfig:" +
              " #of {B2}-Columns Definition: " + numColsB2 );
}


//// == Data Retrieving / ワークフローデータの参照 ==
const inputTable = engine.findDataByNumber( dataIdA ); 
// com.questetra.bpms.core.model.formdata.ListArray (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 / 演算 ==
let outputTable1 = new com.questetra.bpms.core.model.formdata.ListArray();
if( dataIdB !== "" ){
  for( let i = 0; i < inputTable.size() - 0; i++ ){
    let tmpRow = new com.questetra.bpms.core.model.formdata.ListArray.ListRow();
    if( numColsA < numColsB ){
      for( let j = 0; j < numColsA; j++ ){
        tmpRow.addCol( inputTable.getRow(i).getCol(j) );
      }
      for( let j = 0; j < numColsB - numColsA; j++ ){
        tmpRow.addCol( "" ); // Fill with empty characters
      }
    }
    if( numColsA >= numColsB ){
      for( let j = 0; j < numColsB; j++ ){
        tmpRow.addCol( inputTable.getRow(i).getCol(j) );
      }
    }
    outputTable1.addRow( tmpRow );
    engine.log( " AutomatedTask:" +
                " Add B[" + i + "]" );
  }
}

let outputTable2 = new com.questetra.bpms.core.model.formdata.ListArray();
let numOriginLines = 0;
if( dataIdB2 !== "" ){
  if( engine.findDataByNumber( dataIdB2 ) !== null ){
    outputTable2 = engine.findDataByNumber( dataIdB2 ); 
    numOriginLines = engine.findDataByNumber( dataIdB2 ).size() - 0;
  }
  engine.log( " AutomatedTask:" +
              " #of {B2}-Rows: " + numOriginLines );

  for( let i = 0; i < inputTable.size() - 0; i++ ){
    let tmpRow = new com.questetra.bpms.core.model.formdata.ListArray.ListRow();
    if( numColsA < numColsB2 ){
      for( let j = 0; j < numColsA; j++ ){
        tmpRow.addCol( inputTable.getRow(i).getCol(j) );
      }
      for( let j = 0; j < numColsB2 - numColsA; j++ ){
        tmpRow.addCol( "" ); // Fill with empty characters
      }
    }
    if( numColsA >= numColsB2 ){
      for( let j = 0; j < numColsB2; j++ ){
        tmpRow.addCol( inputTable.getRow(i).getCol(j) );
      }
    }
    outputTable2.addRow( tmpRow );
    engine.log( " AutomatedTask:" +
                " Add B2[" + (numOriginLines + i) + "]" );
  }
}


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


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

Download

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.

Notes

  1. Copies text information of all cell values.
  2. Copies in the display order of the column. (Does not refer to column ID)
  3. If the number of columns decreases, the right columns will not be copied.
  4. If the number of columns increases, blank strings will be completed.
  5. To re-order columns, consider Table-TsvString-TsvEdit-Table.
  6. Auto-calculated columns are reevaluated. (Not always the same value)
  7. Use the standard function 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.

See also

Service Task (Data Assignment)
TSV String; Re-order Columns

1 thought on “Table, Duplicate”

  1. Pingback: Data Duplicator (Table) – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top