Converter, Multiline-String to Singleline-CSV-String
Converter, Multiline-String to Singleline-CSV-String
Converts a multiline string to a CSV string. Converts each row of a multiline string as the value of each cell in the CSV. If commas are included they will be deleted in advance. Lines with only line feed code are recognized as empty data.
Configs
  • A1: Set Multiline Text *#{EL}
  • B1: Select STRING DATA that stores Singleline CSV (update)
  • B2: Select STRING DATA that stores Singleline CSV (append)
Script (click to open)
// GraalJS Script (engine type: 2)

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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strMultilineText = configs.get( "StrConfA1" );         /// REQUIRED ///////////////
  if( strMultilineText === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A1: Text} is empty \n" );
  }
const strPocketSinglelineCsv = configs.getObject( "SelectConfB1" ); /// REQUIRED /////////
const strPocketMultilineCsv  = configs.getObject( "SelectConfB2" ); /// REQUIRED /////////


//// == Data Retrieving / ワークフローデータの参照 ==
let strTmp = "";
if( strPocketMultilineCsv !== null ){                       // Pocket defined
  if( engine.findData( strPocketMultilineCsv ) !== null ){  // Data exists
    strTmp = engine.findData( strPocketMultilineCsv );
  }
}


//// == Calculating / 演算 ==

/// Replace `,` to ""
let arrText = strMultilineText.replace(/,/g, '').split( "\n" );

/// Append to Tmp
if( strTmp === "" ){
  strTmp = arrText.join( "," );
}else{
  strTmp = strTmp + "\n" + arrText.join( "," );
}


//// == Data Updating / ワークフローデータへの代入 ==
if( strPocketSinglelineCsv !== null ){
  engine.setData( strPocketSinglelineCsv, arrText.join( "," ) );
}
if( strPocketMultilineCsv !== null ){
  engine.setData( strPocketMultilineCsv,  strTmp );
}

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

/*
Notes:
- When the process arrives, the Text stored in Multiline String data is automatically loaded.
    - Comma-separated values in each row are combined.
    - If the input text contains commas (`,`), they will be deleted in advance.
- The CSV is output as "the simplest comma-separated string".
    - Double quote characters are also preserved unescaped.
- The CSV output has an update mode and an append mode.
    - In the append mode, one CSV line is added.


Notes-ja:
- 案件(プロセス)が到達した際、複数行文字列型データに保存されているテキストが読み込まれます。
    - 各行の値をカンマ区切りで結合されます。
    - 入力テキスト内にカンマ(`,`)が含まれている場合、あらかじめ削除されます。
- 出力されるCSVは「もっともシンプルなカンマ区切り文字列」として出力されます。
    - ダブルクオート文字も、エスケープされていない状態で保持されます。
- CSV出力は、更新モードと追記モードがあります。
    - 追記モードの場合、CSV行が一行追加されます。

*/

Download

2021-11-21 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/converter-multiline-string-to-singleline-csv-string-2021/
The Add-on import feature is available with Professional edition.
Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.

Notes

  • When the process arrives the text stored in multiline String data is automatically loaded.
    • Comma-separated values in each row are combined.
    • If the input text contains commas they will be deleted in advance.
  • The CSV is output as the simplest comma-separated string.
    • Double quote characters are also preserved unescaped.
  • The CSV output has an update mode and an append mode.
    • In the append mode one CSV line is added.

Capture

Converts a multiline string to a CSV string. Converts each row of a multiline string as the value of each cell in the CSV. If commas are contained, they will be deleted in advance. Lines with only line feed code are recognized as empty data.
Converts a multiline string to a CSV string. Converts each row of a multiline string as the value of each cell in the CSV. If commas are contained, they will be deleted in advance. Lines with only line feed code are recognized as empty data.

See also

Leave a Reply

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

%d bloggers like this: