To the basic solution: Pass multiple selected values as a single field – 7.1+ version

Use case description

1. The manger runs a data service returning a list of orders.

2. According to presented details he selects some entries where the performance was exceptional. The contact person in each of these may be rewarded.

3. A second data service gets the name (or id) of each selected contact. In our case as one string field.

Limitation of the former solution

As commented in the first document, it does not support value repetitions. For example:

Step 1: The user may select several entries to reach the following string: Louie;Huey;Louie;Louie;

err_4_errow_text.PNG

Step 2: The user deselects one of the Louie entries from the table:err_5_errow_text.PNG

As seen in the screen shot, this leaves us with Huey;

This happens because the replace() function we use in the Action of deselect replaces each Louie; with an empty string. We now pass the next step a wrong string, one that does not reflect the user selections.

A possible solution

In general, we could use brackets [].  This could serve two purposes:

1. Separating between items.

2. Nesting items with the same value.

Adding an entry

/wp-content/uploads/2013/11/image_fx28_328459.gif

If there is already x[] – replace x[] with x[x[]].

Otherwise – add x[] to the string.

If we already have:  Huey[]

Adding Louies will be like this:

Huey[]Louie[]

Huey[]Louie[Louie[]]

Huey[]Louie[Louie[Louie[]]]

We nest each new Louie in the brackets of the previous one.

Removing an entry

/wp-content/uploads/2013/11/image_fx28_328459.gif

Replace each x[] with an empty string.

Removing Louies shows is as follows (the deepest nested is the one removed):

Huey[]Louie[Louie[Louie[]]]

Huey[]Louie[Louie[]]

Huey[]Louie[]

Huey[]

Finalization

/wp-content/uploads/2013/11/image_fx28_328459.gif

Replace each ] with an empty string.

Optional: replace each [ with the desired delimiter, like ;

For the string: Huey[]Louie[Louie[Louie[]]]

We now get: Huey[Louie[Louie[Louie[

Or possibly: Huey;Louie;Louie;Louie;

This gets us back to the normal flat string representation with a delimiter.

Implementation in Visual Composer

The Application

The running application might look like this:

Step 1 – selection:

run_select_1_arr.PNG

Step 2: Deselect one Louie entry.

Step 3: Pass the result string to the Data Service.

run_select_2_and_pass_arr.PNG

Modeling Steps

1. Add relevant Data Service to the model. Connect input and output:

2.PNG

2. To the table add a Boolean field in the Define Data dialog:

3.PNG

3. Add a Data Share element with a field to contain the user selections:

4.PNG

4. Adding an entry: In the Layout Board, add an Assign Action to the check box control.

Condition: =@select==true

Assigned value:

=IF(CONTAINS(share1@selection, Orders@contact & “[]”),

REPLACE(share1@selection, Orders@contact & “[]”, Orders@contact & “[” & Orders@contact & “[]]”),

share1@selection & Orders@contact & “[]”)

assign_1.PNG

5. Removing an entry: Add another Assign Action to the check box Control.

Condition: =@select==false

Assigned value: =REPLACE(share1@selection, Orders@contact & “[]”, “”)

assign_2.PNG

6. Add a button on the table to trigger the activation of the second data service.

5.PNG

7. Add the second data service to the model – the one getting the selection result. In this example I used a Service Component model to echo the input.

8. Link the Data Share and the second data service. Set the event name of the link to *selection. The * is needed since the event is not coming from the link source – so that it’s a global event listening:

6_.PNG

9. Finalization: In the mapping to the second Data Service we modify the selection string:

=REPLACE(REPLACE(@selection, “]”, “”), “[“, “;”)

This gets us the “normal” flat string representation.

7.PNG

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply