Singleline String, Set Nth Line of Multiline
Singleline String, Set Nth Line of Multiline
Extracts one line of a multi-line string and sets that line in single-line String-type Data Item. The Line ID mut be an integer starting with zero. If the Line ID is not specified, or if a number outside the range is specified, the last line will be extracted.
Configs
  • A: Set Multiline String *#{EL}
  • B: Set Line ID (eg “0”)#{EL}
  • C: Select STRING DATA that stores Extracted Line (update) *
Script (click to open)
// GraalJS Script (engine type: 2)

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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strCandidateLines    = configs.get( "StrConfA" );          /// REQUIRED ///////////
  if( strCandidateLines  === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A: String} is empty \n" );
  }
let   strExtractId         = configs.get( "StrConfB" );          //  not required ///////
      strExtractId         = strExtractId.replace(/,/g, '');
  engine.log( " AutomatedTask Config: LineId: " + strExtractId );
const strPocketExtracted   = configs.getObject( "SelectConfC" ); /// REQUIRED ///////////


//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)


//// == Calculating / 演算 ==
let arrCandidateLines = strCandidateLines.split("\n");
let numLineId = parseInt( strExtractId, 10 );
if( isNaN(numLineId) ){
  numLineId = arrCandidateLines.length - 1;
}else if( numLineId < 0 ){
  numLineId = arrCandidateLines.length - 1;
}else if( numLineId > arrCandidateLines.length - 1 ){
  numLineId = arrCandidateLines.length - 1;
}
engine.log( " AutomatedTask numLineId: " + numLineId +
            " (" + arrCandidateLines.length + ")" );
let strExtracted = arrCandidateLines[ numLineId ];


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( strPocketExtracted, strExtracted );


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

/*
Notes:
- When the process reaches the automated task, the Nth line in the multiline string is extracted.
    - You should specify Line-ID `N` as a zero-based integer.
    - If you want to extract the first line, specify "`0`".

APPENDIX:
- If the Line-ID contains commas, they will be removed and then parsed.
    - Parsing depends on JavaScript `parseInt()`.
- If a line with only line breaks is specified, the single line data will be overwritten with an empty string.

Notes-ja:
- 案件がこの自動処理工程に到達した際、複数行文字列(候補行リスト)内の第N行を自動的に抽出します。
    - 行ID `N` はゼロ始まりの整数で指定してください。
    - もし先頭行を抽出したい場合は "`0`" を指定します。

APPENDIX-ja:
- 行IDにカンマ(桁区切り文字等)が存在する場合、除去された文字列が解析されます。
    - 解析は JavaScript `parseInt()` に依存します。
- 改行のみの行が指定された場合には、単一行文字列データは空文字で上書きされます。
*/

Download

    The Add-on import feature is available with Professional edition.
    Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.

    Notes

    • When the process reaches the automated task, the Nth line in the multiline string is extracted.
      • The Line ID N should be an integer starting from zero.
      • If you want to extract the first line, specify “0“.

    Capture

    Extracts one line of the multi-line string and sets that line in singleline string data. Specify the Line ID as a zero-based integer. If the Line ID is not specified or is out of range, the last line will be extracted.
    Extracts one line of the multi-line string and sets that line in singleline string data. Specify the Line ID as a zero-based integer. If the Line ID is not specified or is out of range, the last line will be extracted.

    Appendix

    • If the Line ID contains commas they will be removed and then parsed.
      • Parsing depends on JavaScript parseInt().
    • If a line with only line breaks is specified the single line data will be overwritten with an empty string.

    See also

    Leave a Reply

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

    %d bloggers like this: