Master Table, Create by TSV String
Master Table, Create by TSV String
Creates a new master file (OptionsXML) by referring to the TSV String. The specified column data are set as Master IDs, and the other data is set as Master Labels. By placing a [Update Choices] in the downstream process, the update task can be automated.
Configs
  • A: Set TSV String *#{EL}
  • B1: Set Column-Number that will be Master-IDs (eg. “0”) *#{EL}
  • B2: Set Separator between Label elements (eg. “*”)#{EL}
  • C0: Set Name of Master File (eg. “foo.xml”) *#{EL}
  • C1: Select FILES DATA for Master File (append) *
  • C2: Select STRING DATA for List of Master IDs (update)
  • C3: Select STRING DATA for List of Master Labels (update)
Script (click to open)

// GraalJS Script (engine type: 2)
// 
// Notes:
// When [service task (update option master)] is placed downstream
// - add Select-Type data item and refer to the ID-list and the Label-list
// - https://support.questetra.com/bpmn-icons/service-task-choices-update/
// - https://questetra.zendesk.com/hc/en-us/articles/360002260151-M208
// 
// Notes(ja):
// 下流に[サービスタスク(選択肢マスタ更新)]を配置する場合
// - 別途、選択肢型データを定義し、ID一覧とLabel一覧を参照させます
// - https://support.questetra.com/ja/bpmn-icons/service-task-choices-update/
// - https://questetra.zendesk.com/hc/ja/articles/360002260151-M208
// 
// id = value, label = display

/*
 Questetra BPMS V12.0 (released 2020-05-11)
 - configs.getObject()
 - engine.findData()
 - engine.setData()
*/

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strTsv                = configs.get( "strSetConfA" )  + "";  // required
const strColumnId           = configs.get( "strSetConfB1" ) + "";  // required
let   strSeparator          = configs.get( "strSetConfB2" ) + "";  // not
const strMasterName         = configs.get( "strSetConfC0" ) + "";  // required
const pocketFilesMaster     = configs.getObject( "SelectConfC1" ); // required
const pocketStrOptionIds    = configs.getObject( "SelectConfC2" ); // not
const pocketStrOptionLabels = configs.getObject( "SelectConfC3" ); // not

if( strTsv === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {TSV A} is empty \n" );
}
const numColumnId = parseInt( strColumnId );
engine.log( " AutomatedTask StringColumnId:" + 
            " String {B1}: " + numColumnId );
if( isNaN( numColumnId ) ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Column-Number B1} is not an integer \n" );
}
engine.log( " AutomatedTask SeparatorInLabel:" + 
            " String {B2}: " + strSeparator );
if( strSeparator === "" ){
  engine.log( " AutomatedTask ConfigWarning:" +
              " Config {strSeparator B2} is empty or not configed" );
//  strSeparator = "*";
}
if( strMasterName === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {MasterFile Name C0} is empty \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
let filesMaster = engine.findData( pocketFilesMaster ); 
if( filesMaster === null ){
  filesMaster = new java.util.ArrayList();
  // java.util.ArrayList
  // - com.questetra.bpms.core.event.scripttask.QfileView
}


//// == Calculating / 演算 ==
let strOptionIds    = "";
let strOptionLabels = "";

const arrStrTsv = strTsv.split("\n");
engine.log( " AutomatedTask StringTsv: " + 
            arrStrTsv.length + " lines" );

let arrTmpRow;
for( let i = 0; i < arrStrTsv.length; i++ ){
  arrTmpRow = arrStrTsv[i].split("\t");
  if( arrTmpRow.length < 2 ){
    throw new Error( "\n AutomatedTask UnexpectedTsvError:" +
                     " #of columns is less than 2 at line " + i + " \n" );
  }
  if( arrTmpRow.length < numColumnId ){
    throw new Error( "\n AutomatedTask UnexpectedTsvError:" +
                     " #of columns is less than Col-Num at line " + i + " \n" );
  }
  for( let j = 0; j < arrTmpRow.length; j++ ){
    if( j === numColumnId ){
      strOptionIds    += arrTmpRow[j] + "\n";
    }else{
      strOptionLabels += arrTmpRow[j] + strSeparator;
    }
  }
  if( strSeparator.length !== 0 ){
    strOptionLabels = strOptionLabels.slice( 0, (- strSeparator.length) );
  }
  strOptionLabels = strOptionLabels + "\n";
}
strOptionIds    = strOptionIds.slice( 0, -1 );
strOptionLabels = strOptionLabels.slice( 0, -1 );

let xmlNew = '<?xml version="1.0" encoding="UTF-8"?><items>\n';
let arrOptionIds    = strOptionIds.split("\n");
let arrOptionLabels = strOptionLabels.split("\n");
for( let i = 0; i < arrOptionIds.length; i++ ){
  xmlNew += '<item value="';
  xmlNew += arrOptionIds[i];
  xmlNew += '" display="';
  xmlNew += arrOptionLabels[i];
  xmlNew += '" />\n';
}
xmlNew += "</items>";

filesMaster.add(
  new com.questetra.bpms.core.event.scripttask.NewQfile(
    strMasterName, "text/xml", xmlNew
  )
);


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( pocketFilesMaster, filesMaster ); // FILES
if( pocketStrOptionIds !== null ){     // STRING
  engine.setData( pocketStrOptionIds, strOptionIds );
}
if( pocketStrOptionLabels !== null ){  // STRING
  engine.setData( pocketStrOptionLabels, strOptionLabels );
}

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

Download

2021-07-29 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/master-table-create-by-tsv-string-2021/
The Add-on import feature is available with Professional edition.

Notes

  1. When a [Update Choices] is placed downstream;

Capture

Creates a new master file (OptionsXML) by referring to TSV String. The specified column data are set as Master IDs, and the others are set as Master Labels. For automation, place [Update Choices] downstream.

See also

1 thought on “Master Table, Create by TSV String”

  1. Pingback: Master Table, Create by TSV String – Questetra Support

Comments are closed.

%d bloggers like this: