TSV String; Add Static Value to All Lines

TSV String; Add Static Value to All Lines

Adds the new string cell to the end of all rows. If there are space characters or line feed characters at the beginning and end of the TSV, they will be deleted beforehand. If the number of tab separators does not match, an error will occur.

2019-07-20 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/tsv-string-add-static-value-to-all-lines/

Configs
  • A: Select STRING DATA for Source TSV *
  • B: Set STRING for New Cell (e.g. “Tax Rate 10%”) #{EL}
  • C: Select STRING DATA for Generated TSV (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 cellStr = configs.get( "conf_CellStr" ) + "";
const dataIdC = configs.get( "conf_DataIdC" ) + ""; // config required
if( cellStr === "" ){
  engine.log( " AutomatedTask StringWarning:" +
              " CellStr is empty" );
}

//// == Data Retrieving / ワークフローデータの参照 ==
if( engine.findDataByNumber( dataIdA ) === null ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} is null \n" );
}
const inputTsv = (engine.findDataByNumber( dataIdA ) + "").trim();
if( inputTsv == "" ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} is empty \n" );
}


//// == Calculating / 演算 ==
let   outputTsv = "";
const arrInputTsv = inputTsv.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A} as TSV, number of lines " + arrInputTsv.length );
const arrHeaderCells = arrInputTsv[0].split("\t");
engine.log( " AutomatedTask SinglelineString:" + 
            " TSV Header, number of cells " + arrHeaderCells.length );

for (let i=0; i < arrInputTsv.length; i++){
  const arrCells = arrInputTsv[i].split("\t");
  if( arrCells.length !== arrHeaderCells.length ){
    throw new Error( "\n AutomatedTask UnexpectedStringError:" + 
      " String {A} as TSV, number of delimiters in each row must be same: Row " + i + "\n");
  }
  outputTsv += arrInputTsv[i] + "\t" + cellStr;
  if( i !== arrInputTsv.length - 1 ){
    outputTsv += "\n";
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
engine.setDataByNumber( dataIdC, outputTsv );


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

Download

Capture

See also

2 thoughts on “TSV String; Add Static Value to All Lines”

  1. Pingback: Multiline String; Delete Header Lines – Questetra Support

  2. Pingback: TSV String; Re-order Columns – Questetra Support

Leave a Reply

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

%d bloggers like this: