0

I fail using a select statement within a foreach loop of a flow.

The foreach loop is meant to iterate through a list of items retrieved from a SharePoint list. The get-items-operation is already filtered by OData and should return either an empty list or only one item. Nevertheless it is a list and has to be iterated within a foreach loop.

Within the loop I then want to extract a certain field from the list. The field is a multiple choice field.

The data which is available within the loop reads:

[
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    "Id": 0,
    "Value": "Brand- & Evak.helfer"
  },
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    "Id": 1,
    "Value": "Ersthelfer"
  },
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    "Id": 2,
    "Value": "SiB"
  }
]

I want to use the content to update a field in a different SP list. As the identity of the ID and the Value is different there, I have to remove the ID. Optimal outcome should look like:

[
  {
    "Value": "Brand- & Evak.helfer"
  },
  {
    "Value": "Ersthelfer"
  },
  {
    "Value": "SiB"
  }
]

I'm unsure, how to fill the boxes in the select element.

I filled the "from"-box with:

items('name_of_comprising_loop')?['name_of_multiple_choice_field']

This seems to be correct, as I can see the data (see first sample) in the input section of the debug view. I then wrote into the first "key"-box:

Value

This seems to make sense as well, considering the output below. And into the first "value"-box:

@items('name_of_comprising_loop')?['name_of_multiple_choice_field/Value']

The outcome unfortunately is:

[
  {
    "Value": null
  },
  {
    "Value": null
  },
  {
    "Value": null
  }
]

I think I really don't understand, how the select operation works.

Update I'm apparently too stupid to understand, why it can't be done with a select operation.

Citing the MS documentation:

Use the Data Operation – Select action to transform the shape of objects in an array. For example, you can add, remove, or rename elements in each object in an array.

Then why is it impossible to transform

[
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    "Id": 0,
    "Value": "Brand- & Evak.helfer"
  },
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    "Id": 1,
    "Value": "Ersthelfer"
  },
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    "Id": 2,
    "Value": "SiB"
  }
]

into

[
  {
    "Value": "Brand- & Evak.helfer"
  },
  {
    "Value": "Ersthelfer"
  },
  {
    "Value": "SiB"
  }
]

with the select operation?

2

Select action takes an array and outputs an array allowing to change the shape of the object in the array, but the number of items still remains the same.

For more information you can refer to this MS Article

However, we can accomplish this goal by using the following steps:

  1. Declare an array variable to hold the multi-choice field's values
  2. Get list items ([Get items]) using a filter so that it returns only one item or null
  3. Add a [Apply to each] action, and as input, add the following expression to get the values from the multi-choice field In this case, [FavoriteColor] is the name of the multi-value field.
first(outputs('Get_items')?['body/value'])?['FavoriteColor']
  1. Within [Apply to each], add [Append to an array] action and use this expression.
{
 "Value": [Expression]items('Apply_to_each')?['Value']
}

  1. using a [Compose] action verify the results

See the screenshots below:

enter image description here

Detail 1

enter image description here

Output

enter image description here

3
  • Thanks for sharing this solution. However, I do not understand, why the "select" operation is not the way to do this. In the examples within the linked description at MS there's one where additional key/value pairs are inserted in each element. So I think it should be possible to remove the two unneeded key/value pairs from each element.
    – Ariser
    Jan 19 at 10:31
  • Since multi-choice field returns an array selected values, you can access in Select like item()?['FavoriteColor'][0]['Value'], item()?['FavoriteColor'][1]['Value'] ,but you're hard-coding it; can't be dynamic. You can get an aggregate (concatenated) result like - * "Value": "Brown , Black"* Jan 19 at 13:43
  • When the return value of a multi-choice field is an array, then it should be the optimal data to be processed with select according to MS documentation. I don't know, why an index must be hard coded here, because then the select operation makes no sense at all? I feel very stupid.
    – Ariser
    Jan 20 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.