Create string of all selected checkbox values

0
Entity A is empty and one of its attributes is "Companies". Entity A has a many-to-many association with Entity B that has a single attribute: 'Companies'   I have a form in which a user updates Entity A's other attributes via text boxes. The user selects companies from a multi-selection combo-box with Entity B as the data source.   I need all the selected companies in the combo box to be concatenated into a string and update the Companies attribute in Entity A but I'm unable to do this.   Mendix docs suggest using the Get Checkbox Set Selector Value function, but I cannot find any examples of how to actually use it.   Has anyone successfully accomplished this?
asked
4 answers
1

Add a microflow that triggers onchange, retrieve the associated records.

Add a create variable activity to create a string and then loop over the retrieved records setting the string variable and then use that value to set the attribute via a change object acvtivity.

This should do the trick.

answered
0

Hi Jeffery,

I'd suggest you to use a microflow in the onChange event that retreives the selected values, create a string variable and loop the selected values in it. Later concatenate the values in the created variable and now store the variable in the desired attribute.

answered
0

Hi Jaffery,

You can use the multiselect widget, and there you can select the attribute where you want to store the selected object in string format.

This way it will be easier without any extra logic.

Multi select widget


Hope it helps!

Let me know if you have any issues,

answered
0

Hi,


In Mendix, a multi-select combo box / checkbox set stores the selected values in the association, not in the string attribute. So to store all selected companies in a string, you must retrieve the associated objects and concatenate them in a microflow.

Steps

1. Domain Model

EntityA
- Companies (String)

EntityB
- CompanyName (String)

Association
EntityA_EntityB (Many-to-Many)

The multi-select combo box should store selections in EntityA_EntityB association.

2. Create a Microflow (on Save button)

Step 1 — Retrieve selected companies

Retrieve EntityB through association:

[EntityA_EntityB = $EntityA]

Result → $CompanyList

Step 2 — Create String variable

$CompanyString = ''

Step 3 — Loop

Loop through $CompanyList.

Inside loop update string:

if $CompanyString = ''
then $IteratorEntityB/CompanyName
else $CompanyString + ', ' + $IteratorEntityB/CompanyName

Step 4 — Update EntityA

Change Object:

$EntityA/Companies = $CompanyString

Commit if needed.

Result

If user selects:

Google
Microsoft
Apple

Stored value becomes:

Google, Microsoft, Apple

Key point

Multi-select widgets → store data in association, not in string attributes.

So the correct approach is retrieve list → loop → build string.

answered