Converter: Table to TSV-String
Converter: Table to TSV-String
Converts Table-type data to a TSV String. The string value of all cells in the Table-type Data Item is copied over TSV string B. Cells with no input are regarded as empty strings.
Configs
  • A: Select TABLE DATA *
  • B: Select STRING DATA (update)
  • B2: Select STRING 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 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.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 / 演算 ==
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

2021-07-30 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/converter-table-to-tsv-string-2021/
The Add-on import feature is available with Professional edition.

Notes

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

Capture

See also

%d bloggers like this: