How to Change Filenames Automatically following the Rule

Filename bulk conversion by using new function of Ver.11.2 released in November, 2016.

Hi, there!

We have released the 11.2 version in November 28, 2016!

Questetra: Cloud BPM v11.2 Enhanced File Auto-generation

I hope you try the various enhanced functions of Ver.11.2 proactively.
(Please contact us if you have any questions!)

By the way, there have been many requests like:

* We would like to rename a file attached as file type data.

If you simply manage the attached file data in Questetra BPM Suite, I do not think you will continue having such requests.

However, for example, if you have the following situation, I think you would like to change the name of the attached file.

* Save file type data in Google Drive.
* Unique names in the save folder or names that serve as identifiers are desirable as filenames.

The enhanced functions of Ver.11.2 enables you to deal with these requests!

Now I would like to introduce how to do it.

== Overview of Implementation Method of Automatic Processing Step ==

There is a newly added function in Ver.11.2 as shown below.

* Script Task / Service Task (Add-on)
[Script Task] become able to update (save) File type Data Items

https://www.questetra.com/info/version-1120/

By using this function, you can change the filename.

“Auto Executing Complicated Data Processing (ECMAScript)”
By placing a Script Step in the middle of the Workflow diagram, data editing by ECMA Script is available. You can automate processing of string editing, for example, calculating the working hours between “Attendance time” and “Quitting time” or, automatically adding the day of the week information to the ‘Operation date’

https://www.questetra.com/tour/m2/m230/

By referring to “File type” of “R2301 Script Data Retrieving / Assignment” in the Manual above and implementing Script Task, you can do this processing.

== Implementation Example of Automatic Processing Step (Script Step)

In this case, suppose it is required to change filenames according to the following rules:

(Based on original filename)
* Prepend date(YYYYMMDD) to the head of original filename and set “_”(underscore) as delimiter
* Append delimiter + Process ID to the last (before “.” + extension) of the original filename
* Convert all the files attached

An implementation example is shown below: (Process ID: 1111 date:2016-12-07)

<Before conversion : filenames of the attached File type Process Data Items>
QuestetraTestDocument.xls
QuestetraTestDocument_ver.1021.doc
<After conversion : filenames of the attached File type Process Data Items>
20161207_QuestetraTestDocument_1111.xls
20161207_QuestetraTestDocument_ver.1021_1111.doc

The code in Script Task for implementing these can be described as:

var fileDataNum = "89";       // File type Process Data Item number
var taskFinishDateNum = "94"; // Date type Process Data item number
var files = data.get(fileDataNum);
var taskFinishDate = new java.text.SimpleDateFormat("yyyyMMdd", new java.util.Locale("ja", "JP", "JP")).format(data.get(taskFinishDateNum));
var newFiles = new java.util.ArrayList();
if (files !== null) {
    for (var i = 0; i < files.size(); i++){
        var file = files.get(i);
        var baseFileName = file.getName().slice(0,file.getName().lastIndexOf("."));
        var extFileName =  file.getName().slice(file.getName().lastIndexOf("."));
        newFiles.add(new com.questetra.bpms.core.event.scripttask.NewQfile(taskFinishDate + "_" + baseFileName + "_" + processInstance.getProcessInstanceId() + "." + extFileName, file.getContentType(), file));
    }
    retVal.put(fileDataNum, newFiles);
}

== More Useful Implementation : Use “Addon-XML” ==

(Though it is not common,) there are cases where multiple “.”(half-widht dots) may be included in the filename, so this example code might include troublesome parts. However, (excluding Lines 9 and 10) as a whole, for a basic code I think it was possible to describe it simply.

Since you can also include business data into the filename, the following benefit can be expected when cooperating with Google Drive.

* Easy to operate filename sorting
* Easy to identify what the file is from filename

In addition, if it is necessary to convert the filename using the same rules in various businesses,
it is preferable to achieve the same conversion regulation easily by packaging it as an “Addon-XML”.

“Create your own Auto-Step for Business Process Definition”
If you want to automate a Processing-step, such as “Obtaining Number of characters and Hash value”, you need to write Scripts using [Script Task]. If you need to use the same [Script Task] in different places, you should consider packaging the Script as an [Addon XML]. (Service-Task Addon)

https://www.questetra.com/tour/m4/m416/

Please feel free to contact us if you have any concerns about implementation.

About Masato Furukubo

Questetra, Inc. Sales Department
View all posts by Masato Furukubo

Recommendations
Prev article - 50. Questetra Tips Analyzing the content of Email, Auto-setting based on it (Part 2)
Next article - 50. Questetra Tips Automate Processing by Accessing its Own API
Another article - Masato Furukubo How to Substitute Approval Step with “Email Reply”

Archive

 RSS