Skip to main content
Version: 10.2.9

Group records by unique column

The article describes setting up a Manual Task with denormalized input data using the unique column name functionality.

This information can be useful, for example, when you want workers to provide a "True/False" answer, but each question will have different answer options (variants). Moreover, each task can have a different number of answer options.

Prepare initial input file

In the following example, a worker should pick up a match action with tool.

seqactiontool 
1Hit NailShovel 
2Hit NailRake 
3Hit NailSaw 
4Hit NailHammer 
5Hit NailHose 
6Cut lawnEdger 
7Cut lawnRake 
8Cut lawnMower 
9Cut lawnHammer 
10Cut lawnScrewdriver

The Manual Task should look like this:

Task Example

The initial file has ten records, but you need only two records with five different answer options. To implement the task using the standard column-answer mapping, create a new task for each record, which is not the right approach.

Therefore, you need to:

  1. Group (merge) records by the action column.

    1. In a selected Manual Task, go to Edit > Run > Advanced Options > Properties.
    2. Enter the appropriate column name into the Unique Column Name field.

    .

  2. On the Design tab, add an Answer with the Check one type. Depending on your task, the Answer type can be Check Multi, Select One, Select Multi, and so on.

  3. Edit the task code to load the Answer options from the tool column. To do this, you need basic CSS, HTML, and JavaScript (jQuery) knowledge.

View file after grouping

Records are merged by the Unique Column. The strings are concatenated using the following delimiter:

♮ - music natural sign (U+266E)

Some text editors can incorrectly display this symbol. Do not forget to use the UTF-8 encoding.

seqactiontool
1♮2♮3♮4♮5Hit NailShovel♮Rake♮Saw♮Hammer♮Hose
6♮7♮8♮9♮10Cut lawnEdger♮Rake♮Mower♮Hammer♮Screwdriver

Design task

Add a new Answer with the Check One type and one option (for example, "One=1").

The option is needed as a prototype for copying and is removed with JavaScript on the next step.

Adding Answer

Edit task code

To load the string from the tool column to Answer options, write the following JS code:

 function splitter(initialString) {
var variants = initialString.split("♮");
var id = $("input[name*='radio']").attr("name");
var hidden = $("input.check-one-hidden[name=" + id + "]");
var etalon = $(".cc-label").clone(true, true);
$(".cc-label").remove();
for (i = 0; i < variants.length; i++) {
var temp = etalon.clone(true, true);
temp.find('[value=1]')
.attr("value", variants[i])
.attr("text", variants[i])
.attr("name", id);
temp.find(".hotkey-text").text(variants[i]);
$(hidden).before(temp);
}
}
window.onload = splitter("${questions[0].data.tool}");

Algorithm

  1. Split the string into an array (variants) using the () delimiter.

  2. Copy the Answer ID into the (id) variable.

  3. Clone and remove the Answer option.

  4. Paste new Answer options with appropriate name, text, and value attributes.

    Answer HTML Code

Run task

To start testing, run the task. The merged records will be correctly displayed only after the Run Task action.

Results