Files, Duplicate

Files, Duplicate

Files, Duplicate

ファイル, 複製

Duplicates File-type data. All files stored in Data Item A1 (Original Files) will be copied over to Data Item B1 (Clone Files). Also possible to change the file name or Content-Type. If the same Data Item is specified as A1 and B1, overwritten.

Auto Step icon
Configs for this Auto Step
SelectConfA1
A1: Select FILE DATA for Original Files *
SelectConfB1
B1: Select FILE DATA that stores new Clone Files (update)
SelectConfB2
B2: Select FILE DATA that stores new Clone Files (append)
StrConfC1
C1: To save-as, Set new File Names (new line delimited)#{EL}
StrConfC2
C2: To change, Set new Content-Types (new line delimited)#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)

//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const filesPocketOriginal = configs.getObject( "SelectConfA1" );  /// REQUIRED ///////////////
  let filesOriginal       = engine.findData( filesPocketOriginal );  // java.util.ArrayList
      // java.util.List of com.questetra.bpms.core.event.scripttask.QfileView
  if( filesOriginal     === null ) {
    throw new Error( "\n AutomatedTask UnexpectedFileError:" +
                     " No File {A1} is attached \n" );
  }else{
    engine.log( " AutomatedTask FilesArray {A1}: " +
                filesOriginal.size() + " files" );
  }
const strFileNamesClone   = configs.get( "StrConfC1" );           // NotRequired /////////////
const arrFileNamesClone   = strFileNamesClone === "" ?
                            [] : strFileNamesClone.split( '\n' );
const strFileTypesClone   = configs.get( "StrConfC2" );           // NotRequired /////////////
const arrFileTypesClone   = strFileTypesClone === "" ?
                            [] : strFileTypesClone.split( '\n' );

const filesPocketCloneUpdate = configs.getObject( "SelectConfB1" );  // NotRequired /////////////
  let filesCloneUpdate       = new java.util.ArrayList();
const filesPocketCloneAppend = configs.getObject( "SelectConfB2" );  // NotRequired /////////////
  let filesCloneAppend       = new java.util.ArrayList();
  if ( filesPocketCloneAppend !== null ) {
    if ( engine.findData( filesPocketCloneAppend ) !== null ) {
      filesCloneAppend       = engine.findData( filesPocketCloneAppend ); // java.util.ArrayList
      engine.log( " AutomatedTask FilesArray {B2}: " +
                  filesCloneAppend.size() + " files" );
    }
  }


//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)


//// == Calculating / 演算 ==
let numOfDuplicate = filesOriginal.size();
  // in case "A1===B2", `filesOriginal.size()` is getting bigger with each filesCloneAppend.add()

for( let i = 0; i < numOfDuplicate; i++ ){
  engine.log( " AutomatedTask '" + filesOriginal.get(i).getName() +
              "' Content-Type: " + filesOriginal.get(i).getContentType() );

  let strTmpName = ( arrFileNamesClone?.[i] === undefined || arrFileNamesClone?.[i] === "" ) ?
                   filesOriginal.get(i).getName() : // If new name not configured, copy original
                   arrFileNamesClone[i] ;
    // https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#size--
    // com.questetra.bpms.core.event.scripttask.QfileView
    // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Optional_chaining

  let strTmpType = ( arrFileTypesClone?.[i] === undefined || arrFileTypesClone?.[i] === "" ) ?
                   filesOriginal.get(i).getContentType() : // If new name not configured, copy original
                   arrFileTypesClone[i] ;

  engine.log( " ------------> '" + strTmpName +
              "' Content-Type: " + strTmpType );

  filesCloneUpdate.add(
    new com.questetra.bpms.core.event.scripttask.NewQfile(
      strTmpName, strTmpType, filesOriginal.get(i)
    )
  );
  filesCloneAppend.add(
    new com.questetra.bpms.core.event.scripttask.NewQfile(
      strTmpName, strTmpType, filesOriginal.get(i)
    )
      // com.questetra.bpms.core.event.scripttask.NewQfile NewQfile()
  );
}


//// == Data Updating / ワークフローデータへの代入 ==
if ( filesPocketCloneUpdate !== null ) {
  engine.setData( filesPocketCloneUpdate, filesCloneUpdate );
}
if ( filesPocketCloneAppend !== null ) {
  engine.setData( filesPocketCloneAppend, filesCloneAppend );
}

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


/*
Notes:
- Used when incorporating a step in which file data is automatically duplicated in the workflow.
    - When a Process token reaches the automatde step, all files of the file type data are automatically duplicated.
    - When you want to backup received files
        - Versioning
        - Revision Control
    - When you want to change the file name or Content-Type
        - Even if you change the Content-type, the actual file remains unchanged.
    - If to overwrite, specify the data item in which Original is stored as the data item in which Clone is stored.
        - If the same data item is specified for A1 and B1, the files will be overwritten.

APPENDIX:
- Use the standard functions for duplicating string, numeric, date, etc. types.
    - BPMN icon: Update Data
        - https://support.questetra.com/bpmn-icons/service-task-data-assignment/
    - M227: Auto Executing Data Binding, Arithmetic Operations
        - https://questetra.zendesk.com/hc/en-us/articles/360002260571-M227
- If no (missing) setting for save-as, the existing file name will be saved as is.
    - The existing file name will be applied even if a blank character is specified.
- Common examples https://en.wikipedia.org/wiki/Media_type
    - `application/javascript`
    - `application/json`
    - `application/ld+json`
    - `application/msword` (.doc)
    - `application/pdf`
    - `application/sql`
    - `application/vnd.api+json`
    - `application/vnd.ms-excel` (.xls)
    - `application/vnd.ms-powerpoint` (.ppt)
    - `application/vnd.oasis.opendocument.text` (.odt)
    - `application/vnd.openxmlformats-officedocument.presentationml.presentation` (.pptx)
    - `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` (.xlsx)
    - `application/vnd.openxmlformats-officedocument.wordprocessingml.document` (.docx)
    - `application/x-www-form-urlencoded`
    - `application/xml`
    - `application/zip`
    - `application/zstd` (.zst)
    - `audio/mpeg`
    - `audio/ogg`
    - `image/avif`
    - `image/jpeg` (.jpg, .jpeg, .jfif, .pjpeg, .pjp)
    - `image/png`
    - `image/svg+xml` (.svg)
    - `model/obj` (.obj)
    - `multipart/form-data`
    - `text/plain`
    - `text/css`
    - `text/csv`
    - `text/html`
    - `text/xml`
- Old Versions
    - Files, Duplicate
        - https://support.questetra.com/addons/files-duplicate-2021/

Notes-ja:
- ワークフロー内に「ファイルデータが自動複製される工程」を組み込みたい場合に利用します。
    - 案件が自動処理工程に到達した際、ファイル型データの全ファイルが自動的に複製されます。
    - 受領ファイルをバックアップしておきたい場合
        - バージョニング
        - リビジョン・コントロール
    - ファイル名や Content-type を変更したい場合
        - Content-type を変更しても、ファイル実態には変更ありません。
    - 上書きしたい場合、Clone を格納するデータ項目に Original が格納されているデータ項目を指定します。
        - A1とB1に同じデータ項目を指定すれば、上書き保存となります。

APPENDIX-ja:
- 文字列型・数値型・日付型などの複製には、標準機能をご活用ください。
    - BPMNアイコン: [データ更新]
        - https://support.questetra.com/ja/bpmn-icons/service-task-data-assignment/
    - M227: 業務データの結合や四則演算が自動実行されるように設定する
        - https://questetra.zendesk.com/hc/ja/articles/360002260571-M227
- 別名保存の設定が無い場合(足りない場合)は、既存のファイル名のまま保存されます。
    - 空文字指定の場合も、既存のファイル名が適用されます。
- 主要な例 https://en.wikipedia.org/wiki/Media_type
    - `application/javascript`
    - `application/json`
    - `application/ld+json`
    - `application/msword` (.doc)
    - `application/pdf`
    - `application/sql`
    - `application/vnd.api+json`
    - `application/vnd.ms-excel` (.xls)
    - `application/vnd.ms-powerpoint` (.ppt)
    - `application/vnd.oasis.opendocument.text` (.odt)
    - `application/vnd.openxmlformats-officedocument.presentationml.presentation` (.pptx)
    - `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` (.xlsx)
    - `application/vnd.openxmlformats-officedocument.wordprocessingml.document` (.docx)
    - `application/x-www-form-urlencoded`
    - `application/xml`
    - `application/zip`
    - `application/zstd` (.zst)
    - `audio/mpeg`
    - `audio/ogg`
    - `image/avif`
    - `image/jpeg` (.jpg, .jpeg, .jfif, .pjpeg, .pjp)
    - `image/png`
    - `image/svg+xml` (.svg)
    - `model/obj` (.obj)
    - `multipart/form-data`
    - `text/plain`
    - `text/css`
    - `text/csv`
    - `text/html`
    - `text/xml`
- 以前のバージョン
    - ファイル, 複製
        - https://support.questetra.com/ja/addons/files-duplicate-2021/
*/

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

  • Used when incorporating a step in which file data is automatically duplicated in the workflow.
    • When a Process token reaches the automated step, all files of the file type data are automatically duplicated.
    • When you want to backup received files
      • Versioning
      • Revision Control
    • When you want to change the file name or Content-Type
      • Even if you change the Content-type, the actual file remains unchanged.
    • If to overwrite, specify the data item in which Original is stored as the data item in which Clone is stored.
      • If the same data item is specified for A1 and B1, the files will be overwritten.

Capture

Duplicates File-type data. All files stored in Data Item A1 (Original Files) will be copied over to Data Item B1 (Clone Files). Also possible to change the file name or Content-Type. If the same Data Item is specified as A1 and B1, overwritten.

Appendix

  • Use the standard functions for duplicating string, numeric, date, etc. types.
  • If no (missing) setting for save-as, the existing file name will be saved as is.
    • The existing file name will be applied even if a blank character is specified.
  • Common examples https://en.wikipedia.org/wiki/Media_type
    • application/javascript
    • application/json
    • application/ld+json
    • application/msword (.doc)
    • application/pdf
    • application/sql
    • application/vnd.api+json
    • application/vnd.ms-excel (.xls)
    • application/vnd.ms-powerpoint (.ppt)
    • application/vnd.oasis.opendocument.text (.odt)
    • application/vnd.openxmlformats-officedocument.presentationml.presentation (.pptx)
    • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.xlsx)
    • application/vnd.openxmlformats-officedocument.wordprocessingml.document (.docx)
    • application/x-www-form-urlencoded
    • application/xml
    • application/zip
    • application/zstd (.zst)
    • audio/mpeg
    • audio/ogg
    • image/avif
    • image/jpeg (.jpg, .jpeg, .jfif, .pjpeg, .pjp)
    • image/png
    • image/svg+xml (.svg)
    • model/obj (.obj)
    • multipart/form-data
    • text/plain
    • text/css
    • text/csv
    • text/html
    • text/xml
  • Old Versions

See Also

Text Files, Convert Character Encoding

Leave a Reply

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

Discover more from Questetra Support

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

Continue reading

Scroll to Top