
Generate Text File
This item converts any text into a file and adds it to a File type data item.
Basic Configs
- Step Name
- Note
Configs for this Auto Step
- File_DataId
- C1: File type data item to save text file *
- conf_DeleteOtherFiles
- C2: Delete other files when saving
- File_Name
- C3: Saving file name *#{EL}
- Text_Data
- C4: Contents of text file *#{EL}
- conf_CharacterEncoding
- C5: Character encoding when saving (UTF-8 if not selected)
- conf_ContentType
- C6: File type when saving (text/plain if not selected)
Notes
- In [C5: Character encoding when saving] you can specify the following types
- UTF-8
- UTF-16BE with BOM
- UTF-16LE with BOM
- UTF-16BE without BOM
- UTF-16LE without BOM
- When the character encoding is not selected, the file will be saved as UTF-8
- In [C6: File type when saving] you can specify the following types
- text/plain
- text/html
- text/xml
- application/json
- When the file type is not selected, the file will be saved as text/plain
Capture

See also
Script (click to open)
- An XML file that contains the code below is available to download
- generator-textfile.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
//////// START "main()" ////////
main();
function main() {
//// == Config Retrieving & Caluculating / 工程コンフィグの参照 & 演算 ==
const textdata = configs.get("Text_Data");
const filename = configs.get("File_Name");
const filedataId = configs.get("File_DataId");
const deleteOtherFiles = configs.getObject("conf_DeleteOtherFiles");
let characterEncoding = configs.get("conf_CharacterEncoding");
let contentType = configs.get("conf_ContentType");
if (filename === "" || filename === null) {
throw new Error("File Name is blank");
}
if (textdata === null) {
textdata = "";
}
if (characterEncoding === "" || characterEncoding === null) {
characterEncoding = 'UTF-8';
}
if (contentType === "" || contentType === null) {
contentType = 'text/plain';
}
myFiles = retrieveData(textdata, filename, filedataId, deleteOtherFiles, characterEncoding, contentType);
updateData(filedataId, myFiles);
}
/**
* テキストデータをファイル型データに変換する
* @param {String} textdata テキストファイルの内容
* @param {String} filename 保存ファイル名
* @param {String} filedataId テキストファイルを保存するファイル型データ項目のデータ定義番号
* @param {boolean} deleteOtherFiles 保存時に他のファイルを削除するかどうか
* @param {String} characterEncoding 保存する際の文字コード
* @param {String} contentType 保存する際のファイルタイプ
* @return {java.util.ArrayList<QfileView>} myFiles テキストデータをファイル型データとして追加した配列
*/
function retrieveData(textdata, filename, filedataId, deleteOtherFiles, characterEncoding, contentType) {
let myFiles;
if (deleteOtherFiles === true) {
myFiles = new java.util.ArrayList();
} else {
// ワークフローデータからファイル型データの配列を取得
myFiles = engine.findDataByNumber(filedataId);// java.util.ArrayList
if (myFiles === null) {
myFiles = new java.util.ArrayList();
}
}
let fileType;
//x-UTF-16LE-BOM について QBPMS では contentType の charset は UTF-16 として扱われる
if (characterEncoding === 'x-UTF-16LE-BOM') {
fileType = `${contentType}; charset=UTF-16`;
} else if (characterEncoding === "UTF-8" && contentType === "application/json") {
//application/json で UTF-8 の場合は、charset 無しで application/json のみ
fileType = "application/json";
} else {
fileType = `${contentType}; charset=${characterEncoding}`;
}
// テキストデータをファイル型データに変換して追加した配列を返す
myFiles.add(
new com.questetra.bpms.core.event.scripttask.NewQfile(
filename,
fileType,
characterEncoding,
textdata
)
);
return myFiles;
}
//// == Data Updating / ワークフローデータへの代入 ==
function updateData(filedataId, myFiles) {
engine.setDataByNumber(filedataId, myFiles);
}