0
       int[] mitems = new int[] { 99, 98, 92, 97, 95 };

        //pass the variable as "@item()"
        var forEachActivity = new ForEachActivity()
        {
            Name = "ForEachActivity",
            IsSequential = false,
            Items = mitems,
            Activities = activities
        };

This does not compile , report error at Items=mitems, expecting Expression and i am not sure how to provide items in Expression.

3 Answers 3

1

This worked for me

Items = new Expression { Value = "@Json('[10, 20, 30, 40, 50]')" }

0

I never created an activity of this type, but I can help a bit with your troubles. If you read the constructor method for the ForEachActivity object, you can see that the items parameter must be an object of the Expression class. When creating an Expression, it takes a string in the value parameter.

It is kind of weird that the documentation (Here: https://learn.microsoft.com/en-us/azure/data-factory/control-flow-for-each-activity#type-properties) says that Items is "An expression that returns a JSON Array to be iterated over." So my guess is that you must pass a String with a json format to create this Expression object.

So what you can do is replace the creation of the mitems object with something like this:

Expression mitems = new Expression("{99, 98, 92, 97, 95 }");

Hope this helped!!

0
0

I was struggling with this too but I think I got it working now. The Items property is an Expression, which would look something like this:

new ForEachActivity
{
  Name = "myForEachLoop",
  IsSequential = false,
  Items = new Expression("@pipeline().parameters.foreachFileList"),
  Activities = new List<Activity>
  {
    ...
  }
}

The pipeline parameters would look something like this

Parameters = new Dictionary<string, ParameterSpecification>
{
  { "foreachFileList", new ParameterSpecification { Type = ParameterType.Array } }
}

And finally, passing the parameters to your pipeline would look something like this:

Dictionary<string, object> arguments = new Dictionary<string, object>
{
  { "foreachFileList", new string[] { "file1.txt", "file2.txt" } }
};

client.Pipelines.CreateRunWithHttpMessagesAsync(resourceGroup, dataFactoryName, pipelineName, arguments)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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