Repeatable Sections with Multiplier

From SMT-X
Jump to: navigation, search

Repeatable sections are a great way to build complex forms with limited effort. Unfortunately, repeating sections can't be linked directly to multiplier steps in the workflow. This is limited to multi-select fields. There is a way to overcome this and that method is described here

Summary of how the objective is achieved

  • Within the repeating section a JSON line is built-up for each value selected in the section
  • Within the repeating section a hidden field is filled with the sequence number of the section
  • Outside the repeating section all JSON parts are merged into a single JSON string
  • Outside the repeating section the hidden field with the sequence number is used to make a multi-selection in a multi-select dropdown list.
  • The workflow needs a multiplier step based on the multi-select list
  • A variable is used per value in the repeating section
  • A webservice of the type SQL query is used to fix the variables within the multiplier instance

Detailed description

Form definition

The JSON line within the section could look like this:

"#REPLACE-FORMFIELD-formName||hidIndex||#Fieldname":"#REPLACE-FORMFIELD-FormName||lbSelectionField||Name#", "#REPLACE-FORMFIELD-formName||hidIndex||#AnotherFieldname":"#REPLACE-FORMFIELD-formName||AnotherField||#"
"1Fieldname":"Selection made in this instance of the repeating section","1AnotherFieldname":"Value typed in a text field for example"

The 1 in front of the fieldname is the hidden field containing the index of the repeating section.

The JSON outside of the section may look like this:

The content could be in case of 3 repetation:
{"1Fieldname":"Selection made in this instance of the repeating section","1AnotherFieldname":"Value typed in a text field for example",
"2Fieldname":"Selection made in the second instance of the repeating section","2AnotherFieldname":"Value2 typed in a text field for example",
"3Fieldname":"Selection made in the third instance of the repeating section","3AnotherFieldname":"Value3 typed in a text field for example"}

The multi-select field that we need to define the multiplier is placed outside the repeating section. Refer to the hidden sequence field (hidIndex) to set the default answer.

Default answer of the multi-select field: #REPLACE-FORMFIELD-formName||hidIndex||$$||#

The multi-select field contains a list of numbers from 1 to the maximum number of repeats allowed in the repeating section. You may define additional columns with a name like Task1, so that this name is displayed in the Multiplier step of the workflow.

Workflow definition

Within the workflow, add a multiplier based on the multi-select list (containing the number range). For each selected value an instance of the multiplier process is created. Now we need to decode the JSON file provided by the hidden field outside the repeating section. And therefore we need the step set variable. This step is chosen because the option to use NCALC is available there. Create a variable for each field in the JSON. Per variable retrieve the correct value in the following way:

The MULTIPLIERDATA||Name reference contains a number, the fieldname is the name of the field that you added into the JSON.

Repeat this for every field in the repeating section

Now we run into the issue that the variable will get a new value when the next multiplier instance is created. And therefore we can't use the variables further in the multiplier. The solution is to define a webservice of the type SQL query that returns what you put into it. Define a SQL webservice like this:

select #PARAIN1# as ParaOut1, #PARAIN2# as ParaOut2 from Version
This query should contain as many ParaIn and ParaOut as you have variables. Use the variables to provide ParaIn values to the query. From now on, you can refer to the query result fields which will not change when the variable changes.