
Converter (Copy File)
This item copies the attachment files of the File type data item to the specified File type data item. If there is only one source file, the file name can be changed.
Basic Configs
- Step Name
- Note
Configs for this Auto Step
- conf_SourceFileDataId
- C1: Source File type data item *
- conf_DestinationFileDataId
- C2: File type data item to copy to *
- conf_DeleteOtherFiles
- C3: Delete other files when saving
- conf_FileName
- C4: File name (named the same as the source file if blank)#{EL}
Notes
- If there are multiple source files, you cannot specify the file name
Capture

See also
Script (click to open)
- An XML file that contains the code below is available to download
- converter-file-copy.xml (C) Questetra, Inc. (MIT License)
- If you are using Professional, you can modify the contents of this file and use it as your own add-on auto step
function main() {
//// == 自動工程コンフィグの参照 / Config Retrieving ==
const sourceFileDef = configs.getObject("conf_SourceFileDataId"); // (returns ProcessDataDefinitionView)
const destinationFileDef = configs.getObject("conf_DestinationFileDataId"); // (returns ProcessDataDefinitionView)
const deleteOtherFiles = configs.getObject("conf_DeleteOtherFiles");
// ワークフローデータからファイル型データの配列を取得。
const sourceFiles = engine.findData(sourceFileDef);
const destinationFiles = engine.findData(destinationFileDef);
// コピー元のファイルがない場合
if (sourceFiles === null) {
throw new Error('Source file is empty.');
}
let fileName = configs.get("conf_FileName");
if (fileName !== "" && fileName !== null) {
if (sourceFiles.size() > 1) {
// ファイル名が指定されていて、コピー元のファイル型データに複数添付されている場合、エラー
throw new Error("Attachment of multiple files can not be named.");
}
}
// コピー元データ項目にあるファイルをコピー
const newFiles = copyFiles(sourceFiles, fileName);
if (deleteOtherFiles === false && destinationFiles !== null) {
// コピー先データ項目に元からあるファイルを残す場合、リストに、残すファイルを追加する
newFiles.addAll(0, destinationFiles); //「先にコピー前から存在するファイル、後にコピーされたファイル」の順番
}
//// == ワークフローデータへの代入 / Data Updating ==
engine.setData(destinationFileDef, newFiles);
}
/**
* ファイルをコピーする
* @param {Qfile} sourceFiles コピー元ファイル
* @param {String} filename 保存ファイル名
* @return {java.util.ArrayList<QfileView>} files コピーファイルを追加した配列
*/
function copyFiles(sourceFiles, fileName) {
const files = new java.util.ArrayList();
for (let i = 0; i < sourceFiles.size(); i++) {
let qfile;
let sourceFilesInfo = sourceFiles.get(i);
if (fileName !== "" && fileName !== null) {
qfile = new com.questetra.bpms.core.event.scripttask.NewQfile(fileName, sourceFilesInfo.getContentType(), sourceFilesInfo);
} else {
qfile = new com.questetra.bpms.core.event.scripttask.NewQfile(sourceFilesInfo.getName(), sourceFilesInfo.getContentType(), sourceFilesInfo); //ファイルデータをそのまま複製保存する
}
files.add(qfile);
}
return files;
}