Multiline String, Get Number of Lines

Multiline String, Get Number of Lines

Gets the number of lines of text. The number of lines that do not count the trailing newline codes can also be stored.

2019-10-30 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/multiline-string-get-number-of-lines/

Configs
  • A: Select STRING DATA for Multiline Text *
  • B: Select NUMERIC DATA for Number of Lines (update)
  • C: Select NUMERIC DATA for Number of Lines Trimmed (update)
Script
// (c) 2019, Questetra, Inc. (the MIT License)

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


//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + ""; // config required
const dataIdB = configs.get( "conf_DataIdB" ) + ""; // config not required
const dataIdC = configs.get( "conf_DataIdC" ) + ""; // config not required


//// == Data Retrieving / ワークフローデータの参照 ==
// Run-time Data Format Check
if( engine.findDataByNumber( dataIdA ) === null ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} is null \n" );
}
const inputText = engine.findDataByNumber( dataIdA ) + "";
const inputText2 = inputText.replace(/[\n]*$/, "");


//// == Calculating / 演算 ==
const arrInputText = inputText.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A}, number of lines " + arrInputText.length );
const arrInputText2 = inputText2.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A}, number of lines trimmed " + arrInputText2.length );


//// == Data Updating / ワークフローデータへの代入 ==
if ( dataIdB !== "" ){ 
  engine.setDataByNumber( dataIdB, new java.math.BigDecimal( arrInputText.length ) );
}
if ( dataIdC !== "" ){ 
  engine.setDataByNumber( dataIdC, new java.math.BigDecimal( arrInputText2.length ) );
}


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

Download

Capture

See also

1 thought on “Multiline String, Get Number of Lines”

  1. Pingback: Questetra BPMS: Process, List All File URLs – Questetra Support

Leave a Reply

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

%d bloggers like this: