Using Future Values

It is possible to use values that are only calculated in the future. This can be done with the aid of two functions.

Create a New Profile

images/download/attachments/21304731/mark_for_future_4b_EN-version-1-modificationdate-1533118867000-api-v2.png

First, we create a simple CSV mapping profile (line separator NL and field separator semicolon), containing a source structure for a header record and several item records. Additionally, we want to calculate the number of items and show it in the destination structure field number_of_items. Following our simple input data.

H;4711;Lobster
I;A-1;Article 1
I;A-2;Article 2
I;A-3;Article 3

Please use the record match code H for the header node and I for the item node. If you have finished the source structure, you can simply create the destination structure by clicking on the 1:1 button. The only thing left to do now is to create the destination field number_of_items in node Header and the calculation field Calc_number_items in node Item.

Create Variables

images/download/attachments/21304731/mark_for_future_5_EN-version-1-modificationdate-1533118867000-api-v2.png

Create a new variable of type Integer and the name var__COUNT_ITEMS.

Calculate Number of Items

images/download/attachments/21304731/mark_for_future_6_EN-version-1-modificationdate-1533118867000-api-v2.png

Use the function calculate and save variable(a,b,c,d,[e]) on calculation field Calc_number_items and set it like in the screenshot above. This will increment the variable var__COUNT_ITEMS for each iteration of node Item by 1.

Write Number of Items in Header Record

images/download/thumbnails/21304731/mark_for_future_1_EN-version-1-modificationdate-1533118867000-api-v2.png

To be able to write the final value of variable var__COUNT_ITEMS in field number_of_items, we need to use the function mark for future value(a).

What is happening here?

The node Header is processed before the node Item. At this point in time, we do not have the final value of variable var__COUNT_ITEMS. For that reason, we use the 'future value' item_counter in field number_of_items.

Write Number of Items

images/download/attachments/21304731/mark_for_future_7_EN-version-1-modificationdate-1533118867000-api-v2.png

To fill the 'future value' item_counter, after all the items have been processed, we create a new node (below node Item) with a calculation field fill_marked_field. This field uses the function replace marked value(a,b).

What is happening here?

Node End is processed at the end of the mapping. The function replace marked value(a,b) replaces the 'future value' item_counter with the final value of variable var__COUNT_ITEMS (parameter b).

Test

images/download/attachments/21304731/mark_for_future_8_EN-version-1-modificationdate-1533118867000-api-v2.png

If you did everything correctly, a test should show you the result shown in the screenshot above.

The Following Is Not Possible

  • The use of destination fields using the function mark for future value(a) as parameters in functions is prevented to avoid complex backtracking.

  • Replacements are only done in the current record! Values cannot be replaced over several records.

Empty Values

images/download/attachments/21304731/mark_for_future_9_EN-version-1-modificationdate-1533118867000-api-v2.png

If function replace marked value(a,b) is not executed, the future value is treated as 'empty'. See the value of node number_of_items in the screenshot above (no value) after the node End had been deactivated. Please also see section Empty Flag.