Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
PWTRyanWhite
Frequent Visitor

The execution of template action 'MainForEach1' failed: the result of the evaluation of 'foreach'

Hi,

 

I'm trying to setup a pipeline that will take a JSON example and pass it through a for-each loop that will be used to post to a API URL. Below is the setup I have intially created. Keep in mind, the for-each loop does work when passing none complex JSON to the loop. 

 

PWTRyanWhite_0-1725987080261.pngPWTRyanWhite_1-1725987121048.png

PWTRyanWhite_2-1725987217144.png

^ above is 'Set Variable2'

 

This is the JSON I am using to pass to the loop

 

[
  {"lane_id": "SEA-MFR", "origin": "SEA", "destination": "MFR", "input_miles": 688},
  {"lane_id": "GSP-GSP", "origin": "SEA", "destination": "GSP", "input_miles": 287},
  {"lane_id": "RDU-RDU", "origin": "RDU", "destination": "RDU", "input_miles": 103},
  {"lane_id": "WGO-WGO", "origin": "WGO", "destination": "WGO", "input_miles": 422},
  {"lane_id": "BWI-BWI", "origin": "BWI", "destination": "BWI", "input_miles": 433},
  {"lane_id": "JAX-JAX", "origin": "JAX", "destination": "JAX", "input_miles": 464},
  {"lane_id": "GSP-GSP", "origin": "GSP", "destination": "GSP", "input_miles": 275},
  {"lane_id": "MDT-MDT", "origin": "MDT", "destination": "MDT", "input_miles": 688},
  {"lane_id": "MOB-MOB", "origin": "MOB", "destination": "MOB", "input_miles": 749},
  {"lane_id": "BOS-BOS", "origin": "BOS", "destination": "BOS", "input_miles": 799},
  {"lane_id": "CLT-CLT", "origin": "CLT", "destination": "CLT", "input_miles": 235},
  {"lane_id": "WGO-WGO", "origin": "WGO", "destination": "WGO", "input_miles": 434},
  {"lane_id": "PHL-PHL", "origin": "PHL", "destination": "PHL", "input_miles": 528}
]

 

 

PWTRyanWhite_3-1725987359874.png

^ This is from 'Set variable1'

 

1 ACCEPTED SOLUTION

Found a resolution using parameters and introducing it directly to the copy activity. No need for more energy on this ticket.

View solution in original post

4 REPLIES 4
v-nuoc-msft
Community Support
Community Support

Hi @PWTRyanWhite 

 

According to the screenshot you provided, the error message for Set Variable2 indicates that the expression type you used in the "Set Variable2" step was a string, but the field expected an object type.

 

If your current expression returns a string, you can try using the json() function to convert the string into an object.

 

Suppose the expression you use in "Set Variable2" is:

 

@variables('Variable1')

 

You can try changing it to:

 

@json(variables('Variable1'))

 

The process might look something like this:

 

Set Variable1 stores JSON data.

 

@json(
'[
{"lane_id": "SEA-MFR", "origin": "SEA", "destination": "MFR", "input_miles": 688}, 
{"lane_id": "GSP-GSP", "origin": "SEA", "destination": "GSP", "input_miles": 287}
]'
)

 

Set Variable2 processes or converts data.

 

@json(variables('Variable1'))

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Found a resolution using parameters and introducing it directly to the copy activity. No need for more energy on this ticket.

Hi @PWTRyanWhite 

 

Thank you for sharing, if you have any questions, please continue to let us know in the forum!

 

Regards,

Nono Chen

Unfortunately, after changing to the @Json format, I am getting this error: The variable 'mind_SYMBOL' of type 'String' cannot be initialized or updated with value of type 'Array'. The variable 'mind_SYMBOL' only supports values of types 'String'.

 

PWTRyanWhite_0-1726071557037.png

 

BTW, not sure if I sent you what the variable setup looks like:

 

PWTRyanWhite_1-1726071624667.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.