Master Table, Update

Master Table: Update
Master Table, Update

Creates a new master file (OptionsXML) by referring to the master table on Workflow Platform. A new ID-Label will be added to the first line. Rows with the same ID are deleted. For automation, place [Service Task (Choices Update)] downstream.

(C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/master-table-update/

Configs
  • A: Set Name of Master File (e.g. “foo.xml”) * #{EL}
  • B1: Set ID (Value) to be added * #{EL}
  • B2: Set Label (Display) to be added * #{EL}
  • C1: Select FILE DATA for New Master File (append) *
  • C2: Select STRING DATA for List of Master IDs (update)
  • C3: Select STRING DATA for List of Master Labels (update)
  • D1: Select FILE DATA to Backup Current Master (append)
  • D2: Select STRING DATA to Backup Deleted ID-Label (update)
Script (click to open)

// Nashorn Script (engine type: 1)
// 
// Notes:
// It is also possible to add multiple ID-Labels in bulk
// Name of created file are "Foo.xml" and "Foo-backup.xml"
// If the specified master file does not exist, only new file will be created.
// 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をまとめて追加することも可能です
// 生成されるファイル名は "Foo.xml" および "Foo-backup.xml" となります
// マスターファイルが存在しない場合、新規ファイルが生成されます
// 下流に[サービスタスク(選択肢マスタ更新)]を配置する場合
// - 別途、選択肢型データを定義し、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 strMasterName         = configs.get( "strSetConfA"  ); // required
const strComingOptionIds    = configs.get( "strSetConfB1" ); // required
const strComingOptionLabels = configs.get( "strSetConfB2" ); // required
const pocketNewMaster       = configs.getObject( "SelectConfC1" ); // required
const pocketNewOptionIds    = configs.getObject( "SelectConfC2" ); // not
const pocketNewOptionLabels = configs.getObject( "SelectConfC3" ); // not
const pocketBackupMaster    = configs.getObject( "SelectConfD1" ); // not
const pocketDeletedIdLabels = configs.getObject( "SelectConfD2" ); // not

if( strMasterName === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {MasterFile Name A} is empty \n" );
}
if( strComingOptionIds === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {OptionID B1} is empty \n" );
}
if( strComingOptionLabels === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {OptionLabel B2} is empty \n" );
}
let arrComingOptionIds    = strComingOptionIds.split('\n');
let arrComingOptionLabels = strComingOptionLabels.split('\n');
if( arrComingOptionIds.length !== arrComingOptionLabels.length ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " {OptionIds B1} {OptionLabels B2} must be same \n" );
}


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


//// == Calculating / 演算 ==
const jarrOptions = itemDao.findAll( strMasterName, true );
// return "List<ItemView>" (java.util.ArrayList)
// M319: Register an Options-XML file to which the Process Model Definitions Refer
// M319: Options-XML: 複数の業務プロセス定義から参照される選択肢XML
// R2300 com.questetra.bpms.core.event.scripttask.ItemDaoWrapper

let strNewOptionIds    = "";
let strNewOptionLabels = "";
let strDeletedIdLabels = "";
let xmlBackup = '<?xml version="1.0" encoding="UTF-8"?><items>\n';
if( jarrOptions.size() - 0 === 0 ){
  engine.log( " AutomatedTask OptionsXML: " + 
            strMasterName + " not found" );
  strNewOptionIds    += strComingOptionIds;
  strNewOptionLabels += strComingOptionLabels;
}else{
  engine.log( " AutomatedTask OptionsXML: " + 
            strMasterName + ": " +
            jarrOptions.size() + " options" );
  strNewOptionIds    += strComingOptionIds + "\n";
  strNewOptionLabels += strComingOptionLabels + "\n";

  let flagMatch = 0;
  for( let i = 0; i < (jarrOptions.size() - 0); i++ ){
    xmlBackup += '<item value="';
    xmlBackup += jarrOptions.get(i).getValue();
    xmlBackup += '" display="';
    xmlBackup += jarrOptions.get(i).getDisplay();
    xmlBackup += '" />\n';
    for( let j = 0; j < arrComingOptionIds.length; j++ ){
      if( (jarrOptions.get(i).getValue() + "") === arrComingOptionIds[j] ){
        flagMatch = 1;
        break;
      }
    }
    if( flagMatch === 0 ){
      strNewOptionIds    += jarrOptions.get(i).getValue() + "\n";
      strNewOptionLabels += jarrOptions.get(i).getDisplay() + "\n";
    }else{
      strDeletedIdLabels += jarrOptions.get(i).getValue() + "\t" +
                            jarrOptions.get(i).getDisplay() + "\n";
    }
    flagMatch = 0;
  }
  strNewOptionIds    = strNewOptionIds.slice( 0, -1 );
  strNewOptionLabels = strNewOptionLabels.slice( 0, -1 );
  strDeletedIdLabels = strDeletedIdLabels.slice( 0, -1 );
}
xmlBackup += "</items>";

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

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


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( pocketNewMaster, filesNewMaster ); // FILES
if( pocketNewOptionIds !== null ){     // STRING
  engine.setData( pocketNewOptionIds, strNewOptionIds );
}
if( pocketNewOptionLabels !== null ){  // STRING
  engine.setData( pocketNewOptionLabels, strNewOptionLabels );
}
if( pocketBackupMaster !== null ){     // FILES
  let filesBackupMaster = engine.findData( pocketBackupMaster ); 
  if( filesBackupMaster === null ){
    filesBackupMaster = new java.util.ArrayList();
  }
  let dateNow = new Date();
  let strYYYYMMDDHHMM = "";
      strYYYYMMDDHHMM += dateNow.getFullYear();
      strYYYYMMDDHHMM += ('0' + (dateNow.getMonth() + 1)).slice(-2);
      strYYYYMMDDHHMM += ('0' + dateNow.getDate()).slice(-2);
      strYYYYMMDDHHMM += ('0' + dateNow.getHours()).slice(-2);
      strYYYYMMDDHHMM += ('0' + dateNow.getMinutes()).slice(-2);
  let strBackupName = "";
  let arrNameParts = strMasterName.split('.');
  if( arrNameParts.length === 1 ){
    strBackupName += strMasterName + "-" + strYYYYMMDDHHMM;
  }else{
    for( let i = 0; i < arrNameParts.length - 1; i++ ){
      strBackupName += arrNameParts[i];
    }
    strBackupName += "-" + strYYYYMMDDHHMM;
    strBackupName += "." + arrNameParts[arrNameParts.length - 1];
  }
  filesBackupMaster.add(
    new com.questetra.bpms.core.event.scripttask.NewQfile(
      strBackupName, "text/xml", xmlBackup
    )
  );
  engine.setData( pocketBackupMaster, filesBackupMaster );
}
if( pocketDeletedIdLabels !== null ){  // STRING
  engine.setData( pocketDeletedIdLabels, strDeletedIdLabels );
}

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

Download

Capture

Creates a new master file (OptionsXML) by referring to the master table on Workflow Platform. A new ID-Label will be added to the first line. Rows with the same ID are deleted. For automation, place [Service Task (Choices Update)] downstream.

Notes

  1. It is also possible to add multiple ID-Labels in bulk
  2. Name of created file are “Foo.xml” and “Foo-YYYYMMDDHHMM.xml”
  3. If the specified master file does not exist, only new file will be created.
  4. When [service task (update option master)] is placed downstream
    1. add Select-Type data item and refer to the ID-list and the Label-list
    2. https://support.questetra.com/bpmn-icons/service-task-choices-update/
    3. https://questetra.zendesk.com/hc/en-us/articles/360002260151-M208

See also

4 thoughts on “Master Table, Update”

  1. Pingback: Master Table, Backup – Questetra Support

  2. Pingback: Master Table, List All Options as TSV String – Questetra Support

  3. Pingback: Master Table, Update to Delete Options – Questetra Support

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

Leave a Reply

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

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading