Master Table, Update to Delete Options
Master Table, Update to Delete Options

Deletes unnecessary Options and Creates a new master file (OptionsXML) by referring to the master table on Workflow Platform. No error occurs even if the deletion ID does not exist. For automation, place [Service Task (Choices Update)] downstream.

2020-06-16 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/master-table-update-to-delete-options/

Configs
  • A: Set Name of Master File (e.g. “foo.xml”) * #{EL}
  • B: Set ID (Value) of the Option that should be deleted * #{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
// Nashorn Script (engine type: 1)
// 
// Notes:
// It is also possible to delete multiple ID-Labels in bulk
// Name of created file are "Foo.xml" and "Foo-YYYYMMDDHHMM.xml"
// When [Service Task (Choice Update)] 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
// - M319: Register an Options-XML file to which the Process Model Definitions Refer
// - https://questetra.zendesk.com/hc/en-us/articles/360002262551-M319
// 
// Notes(ja):
// 複数のID-Labelをまとめて削除することも可能です
// 生成されるファイル名は "Foo.xml" および "Foo-YYYYMMDDHHMM.xml" となります
// マスターファイルが存在しない場合、新規ファイルが生成されます
// 下流に[サービスタスク(選択肢マスタ更新)]を配置する場合
// - 別途、選択肢型データを定義し、ID一覧とLabel一覧を参照させます
// - https://support.questetra.com/ja/bpmn-icons/service-task-choices-update/
// - https://questetra.zendesk.com/hc/ja/articles/360002260151-M208
// - M319: 複数の業務プロセス定義から参照される選択肢XMLを登録する
// - https://questetra.zendesk.com/hc/ja/articles/360002262551-M319
// 
// 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 strDeleteOptionIds    = configs.get( "strSetConfB" ); // 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( strDeleteOptionIds === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {OptionID B} is empty \n" );
}
let arrDeleteOptionIds = strDeleteOptionIds.split('\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
if( jarrOptions.size() - 0 === 0 ){
  throw new Error( "\n AutomatedTask UnexpectedOptionsXmlError:" +
                   strMasterName + " not found or null \n" );
}
engine.log( " AutomatedTask OptionsXML: " + 
            strMasterName + ": " +
            jarrOptions.size() + " options" );

let strNewOptionIds    = "";
let strNewOptionLabels = "";
let strDeletedIdLabels = "";
let xmlBackup = '<?xml version="1.0" encoding="UTF-8"?><items>\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 < arrDeleteOptionIds.length; j++ ){
    if( (jarrOptions.get(i).getValue() + "") === arrDeleteOptionIds[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

Deletes unnecessary Options and Creates a new master file (OptionsXML) by referring to the master table on Workflow Platform. No error occurs even if the deletion ID does not exist. For automation, place [Service Task (Choices Update)] downstream.

Notes

  1. It is also possible to delete multiple ID-Labels in bulk
  2. Name of created file are “Foo.xml” and “Foo-YYYYMMDDHHMM.xml”
  3. When [Service Task (Choice Update)] is placed downstream

See also

Leave a Reply

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

%d bloggers like this: