Trouble-free! How to Perform an Options-XML Update? (Service Task Addon ed.)

Let's create an automatic process which updates "Choices Master" using Service Task Addon !

Hi, there!

We get many inquiries about options-XML update.
In many cases, we are requested to propose solutions that make master information more convenient and easy to manage.

We introduced the cases in the following blog post before.

Trouble-free! How to Perform an Options-XML Update?
Then, improve “Options-XML Updating Procedure” and make it more convenient!

* Making it more convenient
Without downloading/uploading shared files, perform automatic updates by inputting them.
* Improve
Avoid update undos as much as possible even if multiple administrators do updates asynchronously.

We received the following opinion to this post:

* Since we need to update various options-XML, it is troublesome to copy and paste the contents of the Script Task one by one in each of the created process models
* We often make mistakes not only to copy and paste, but also when the changing Process Data item number

Among others, these are reasonable impressions.
I will propose an implementation method in a form that makes it easier and less prone to mistakes.

== Implementation by integrating a Definition File of Automatic Processing Step ==

I think it is possible to respond to those impressions by integrating Script Task into the definition file (Service Task Addon).

Adding an Auto-Step to be Used for Business Process Definition
When you want to automate Processing-steps, such as “Obtaining Number of characters and Hash value”, it is impossible to define them using only a standard [Service Task] and [Event] (You must use [Script Task] ). However, you will be able to automate your business easily by importing [Addon XML], such as “Number of Character Counter-addon.xml” or “SHA Hash-addon.xml”, in advance. (Service-Task Addon)

Compared with the Process Model introduced in the “Trouble-free! How to Perform an Options-XML Update?”,

<Options-XML Updating Process Model>

The Model by “Service Task Addon” is shown below.

<Options-XML Updating Process Model: Service Addon ver.>

It looks almost the same. (What is the difference?)
However, the settings by GUI has made it easier and less mistakes to use it.

<Data Updating Process (Service Task Addon)>

* Select a Process Data item corresponding to the Options-XML data to be updated in the pull down menu. (Select the String type multi-line data)
* Select a Process Data item corresponding to the Options-XML data for updating (Value, Display, Choices data) in the pull down menu.
“Value”, “Display” : Select String type multi-line data
“Choices data” : Select Choices type data

Although the filename of the Options-XML to be updated must be described, the others will be selected by the name of the Process Data item, and it will result in less mistakes.

== Data Updating Process (Service Task Addon) Code Example ==

<?xml version="1.0" encoding="UTF-8"?><service-task-definition>

<label>Master Updating Data Generation Service</label>

  <config name="conf_MasterFile" required="true" form-type="TEXTFIELD">
    <label>Describe filename of master data to be updated</label>
<config name="conf_TargetData" required="true" form-type="SELECT" select-data-type="STRING_TEXTAREA">
    <label>Select the record data to be updated</label>
  <config name="conf_MasterSourceId" required="true" form-type="SELECT" select-data-type="STRING_TEXTAREA">
    <label>Select the textarea (ID) data for updates</label>
  <config name="conf_MasterSourceDisplay" required="true" form-type="SELECT" select-data-type="STRING_TEXTAREA">
    <label>Select the textarea (Display) data for updates</label>
  <config name="conf_CheckResult" required="true" form-type="SELECT" select-data-type="SELECT_SINGLE">
    <label>Select the update check result data</label>

// Master Updating Script (ver. 20170209)
// Process the specified data record by addition/updates/deletion type.
// (c) 2017, Questetra, Inc. (the MIT License)

//// == Config Retrieving ==
var masterFileName = configs.get( "conf_MasterFile" );  // return the filename of Choices Master
var targetDataNum = configs.get( "conf_TargetData" ); // (returns Number)
var masterSourceIdNum = configs.get( "conf_MasterSourceId" ); // (returns Number)
var masterSourceDisplayNum = configs.get( "conf_MasterSourceDisplay" ); // (returns Number)
var checkResultNum = configs.get( "conf_CheckResult" ); // (returns Number)

//// == Data Retrieving, Data Define ==
var sep = "\n";
var targetDatas = new String(data.get(targetDataNum)).split(sep);
var masterSourceIds = "";
var masterSourceDisplays= "";
var checkResult = "false";

//// == Calculating ==
// Retrieve target master
var items = itemDao.findAll(masterFileName, true);
// Update/Delete record
for (var i = 0; i < items.size(); i++){
	var matchKind = "";
	for (var j = 0; j < targetDatas.length; j++){
		var cols = targetDatas[j].split(",");
		if (items.get(i).getValue() == cols[1]){
			if (cols[0] == "U"){
				matchKind = "update";
				masterSourceIds += items.get(i).getValue() + "\n";
				masterSourceDisplays += cols[2] + "\n";
				checkResult = "true";
			if (cols[0] == "D"){
				matchKind = "delete";
				checkResult = "true";
	if (matchKind == ""){
		masterSourceIds += items.get(i).getValue() + "\n";
		masterSourceDisplays += items.get(i).getDisplay() + "\n";
// Add record
for (var j = 0; j < targetDatas.length; j++){
	var cols = targetDatas[j].split(",");
	if (cols[0] == "I"){
		// If an additional record already exist, do not set it
		if (masterSourceIds.indexOf(cols[1] + "\n") == -1){
			masterSourceIds += cols[1] + "\n";
			masterSourceDisplays += cols[2] + "\n";
			checkResult = "true";
masterSourceIds = masterSourceIds.replace(/\n$/,"") ;          // Delete last newline
masterSourceDisplays = masterSourceDisplays.replace(/\n$/,""); // Delete last newline

// for Debug

//// == Data Updating ==
retVal.put( masterSourceIdNum, masterSourceIds);
retVal.put( masterSourceDisplayNum, masterSourceDisplays );
retVal.put( checkResultNum, [checkResult]);




The data format of “update target record data” input into this service task is the same as the format defined in “Trouble-free! How to Perform an Options-XML Update?”.
For more improvements,

* Perform error check more strictly
* Log a processing skip when adding the existing data or deleting the data that does not exist

can be considered.

== Afterword ==

This case is one pattern to replace the content implemented by Script task with Service Task Addon.
I would like to continue introducing more patterns often used.

As for the implementation of more efficient automatic processing, I think you can consider its use or improvement.
Please feel free to contact us should you have any questions.

== Workflow Sample ==


About Masato Furukubo

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

Prev article - 50. Questetra Tips Automate Processing by Accessing its Own API
Next article - 50. Questetra Tips Can Backlog and Cloud BPM Cooperate?
Another article - Masato Furukubo Implement Customer Master using Options-XML (Part 1)