Add possibility to handle array of values into single entity

Created on 31 March 2025, 27 days ago

Problem/Motivation

I want to be able to create an external entity with multiple items.
Example :
into my response, an item (entity) is an array of value like :

[
  {
    "firstName":"John",
    "lastNaam":"Doe",
  },
  {
    "firstName":"James",
    "lastNaam":"Bond",
  }
]

I'm using then custom_field module to create multiple "people item" base on that answer.

I saw that in the RestClient storage, if the answer is an array we only take the first element of it.

Steps to reproduce

- Configure an external entity that has an array as value for a single value (see example).
- Create a field with custom_field module to be able to map this custom_field with multiple values.
- See that you only have the first element of the response.

Proposed resolution

I propose to check if the array is bigger than 1, then we dont take only the first item but the entire array.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium arwillame Belgium 🇧🇪

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

Merge Requests

Comments & Activities

  • Issue created by @arwillame
  • Pipeline finished with Success
    27 days ago
    Total: 344s
    #461472
  • First commit to issue fork.
  • 🇫🇷France guignonv Montpellier

    Looks good. Just to make sure I understand everything, it means you would get a single entity with no text keys and you will have to map numeric "keys" to fields then, right?

  • 🇧🇪Belgium arwillame Belgium 🇧🇪

    Correct, i create a custom_field "Expertise Item field" that have a "firstname" and "lastname" field.
    Then i can map then like : firstname => $.*.firstName
    This will populate the "Expertise Item field" with multiple items with each have "firstname" and "lastname" filled in.

  • Pipeline finished with Success
    26 days ago
    Total: 229s
    #462380
  • 🇫🇷France guignonv Montpellier
  • 🇫🇷France guignonv Montpellier
  • 🇫🇷France guignonv Montpellier

    @arwillame, could you add a test in RestClientFunctionalTest.php to test your use case and ensure the fix remains stable in the future?
    Your use case could be documented in the test to avoid regressions.

  • 🇨🇦Canada colan Toronto 🇨🇦
  • Merge request !83Resolve #3516385 → (Open) created by arwillame
  • 🇧🇪Belgium arwillame Belgium 🇧🇪

    I found an issue with this logic.
    I have cases where the result is indeed an array because multiple value are possible, but if there is only one result anyway, i want to keep the same logic as it was multiple.
    I think the best would be to just remove the code that makes the "reset($array)" to avoid this issue.
    The handling of an array of a single value should not be handled in code but in the field mapping.
    I created a new MR for this proposal.

  • Pipeline finished with Success
    19 days ago
    Total: 230s
    #468379
  • Pipeline finished with Success
    19 days ago
    Total: 227s
    #468400
  • 🇧🇪Belgium arwillame Belgium 🇧🇪
Production build 0.71.5 2024