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.
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 (click to open)
// GraalJS Script (engine type: 2)
// (c) 2021, 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

The Add-on import feature is available with Professional edition.

Capture

%d bloggers like this: