Converter: Table to TSV-String
Converter: Table to TSV-String

Converts Table-type data to TSV String. The string value of all cells in the Table-type data is copied over TSV string B. Cells with no input are regarded as empty strings.

2020-03-02 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/converter-table-to-tsv-string/

Configs
  • A: Select TABLE DATA *
  • B: Select STRING DATA (update)
  • B2: Select STRING DATA (append)
Script
// Nashorn Script (engine type: 1)
// 
// Notes:
// Copies text information of all cell values.
// Copies in the display order of the column. (Does not depend on column ID)
// The value of Select-column is the option id. (Choice ID; not the displayed Label)
// To add data without erasing already stored cell data, use B2.
//
// Notes (ja):
// 全てのセル値の文字情報をコピーします。
// カラムの表示順にコピーします。(カラムIDに依らない)
// 選択カラムは、選択肢IDが出力されます。(表示テキストではありません)
// 既に格納されているセルデータを消さずに追記したい場合は、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 );


//// == 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 outputTsv1 = "";
if( dataIdB !== "" ){
  for( let i = 0; i < inputTable.size() - 0; i++ ){
    for( let j = 0; j < numColsA; j++ ){
      outputTsv1 += inputTable.getRow(i).getCol(j) + "";
      if( j !== numColsA - 1 ){
        outputTsv1 += "\t";
      }
    }
    if( i !== inputTable.size() - 1 ){
      outputTsv1 += "\n";
    }
  }
}

let outputTsv2 = "";
if( dataIdB2 !== "" ){
  if( engine.findDataByNumber( dataIdB2 ) !== null ){
    outputTsv2 = engine.findDataByNumber( dataIdB2 ) + "\n";
  }
  for( let i = 0; i < inputTable.size() - 0; i++ ){
    for( let j = 0; j < numColsA; j++ ){
      outputTsv2 += inputTable.getRow(i).getCol(j) + "";
      if( j !== numColsA - 1 ){
        outputTsv2 += "\t";
      }
    }
    if( i !== inputTable.size() - 1 ){
      outputTsv2 += "\n";
    }
  }
}


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

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

Download

Capture

Converts Table-type data to TSV String. The string value of all cells in the Table-type data is copied over TSV string B. Cells with no input are regarded as empty strings.

Notes

  1. Copies text information of all cell values.
  2. Copies in the display order of the column. (Does not depend on column ID)
  3. The value of Select-column is the option id. (Choice ID; not the displayed Label)
  4. To add data without erasing already stored cell data, use B2.

See also

1 thought on “Converter: Table to TSV-String”

  1. Pingback: Converter (Table to TSV) – Questetra Support

Leave a Reply

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

%d bloggers like this: