- 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
//////// 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 contentType = configs.get("conf_ContentType");
if (filename === "" || filename === null) {
throw new Error("File Name is blank");
}
if (contentType === "" || contentType === null) {
contentType = 'text/plain';
}
myFiles = retrieveData(textdata, filename, filedataId, deleteOtherFiles, contentType);
updateData(filedataId, myFiles);
}
/**
* テキストデータをファイル型データに変換する
* @param {String} textdata テキストファイルの内容
* @param {String} filename 保存ファイル名
* @param {String} filedataId テキストファイルを保存するファイル型データ項目のデータ定義番号
* @param {boolean} deleteOtherFiles 保存時に他のファイルを削除するかどうか
* @param {String} contentType 保存時に他のファイルを削除するかどうか
* @return {java.util.ArrayList<QfileView>} myFiles テキストデータをファイル型データとして追加した配列
*/
function retrieveData(textdata, filename, filedataId, deleteOtherFiles, 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();
}
}
if (textdata === null) {
textdata = "";
}
// テキストデータをファイル型データに変換して追加した配列を返す
myFiles.add(
new com.questetra.bpms.core.event.scripttask.NewQfile(
filename,
`${contentType}; charset=UTF-8`,
textdata
)
);
return myFiles;
}
//// == Data Updating / ワークフローデータへの代入 ==
function updateData(filedataId, myFiles) {
engine.setDataByNumber(filedataId, myFiles);
}