How to add value to multi-value field without loosing existing values?

Created on 19 November 2019, about 5 years ago
Updated 2 February 2024, 11 months ago

Hi,

To be short:
When using "Set field value" action to a multi-value field within a "Loop through a view result variable" action, only the last result of the view is saved.
How can I have kind of "Add value to multi-value field" action that'll keep already existing values so the loop will add all found values?

To be more descriptive:

  • I have a "Countries" taxonomy that lists countries.
  • And a "Regions" taxonomy listing regions. This vocabulary has an entity reference field "Countries included" (infinite values) to add countries that belongs to it. For example, the "North America" region references Canada and USA countries (let's keep the list short ;-).
  • The user account has a "Country" field referencing the "Countries" taxonomy so users can set their own country. One country per user.
  • The user account also has a "Regions" field referencing the "Regions" taxonomy (hidden to regular users). That field is multi-valued because a country can be part of several regions (let's imagine we have North America and America regions: Canada will be referenced by both regions so the user should reference both regions too).

Now, my goal by using Business Rules is to set user's regions knowing the country.
My setup is working quite good because if I display a message within the loop, the matching regions are listed as expected.
But using the "Set field value" action to the user account "Regions" field, the found regions are added but they replace the existing values so only the last result of the loop is saved.
And yes, I've written my "Set field value" action value field starting with a pipe ;-)

Is there a way to write the "Set field value" action value field so it adds value and not replaces?
Or should I go through a temporary variable to store the found regions list and then set the user regions value with that list.
Or do we need missing action: "Add value to list field"?

Any guidance will be appreciate.
Thanks.

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France PhilY πŸ‡ͺπŸ‡ΊπŸ‡«πŸ‡· Paris, France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024