title: Azure Data Factory get data from foreach value
body: <p>I've a lookup activity with gets value from a container within a blob.  I've a foreach activity which is connected to the lookup activity </p>
  
  <p><a href="https://i.stack.imgur.com/opMm2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/opMm2.png" alt="enter image description here"></a></p>
  
  <p>and under settings it has the value:</p>
  
  <pre><code>@activity('LookupMessageType').output.value
  </code></pre>
  
  <p>I've another copy activity which runs within this foreach activity.  It copies data from cosmos DB to Azure Data Lake.<br>
  <a href="https://i.stack.imgur.com/MMcmy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MMcmy.png" alt="enter image description here"></a></p>
  
  <p>This is the query in the source dataset:</p>
  
  <pre><code>select c.Tag, data.assetTag, data.timestamp, data.jsonVersion, data.messageType, data.speed from c join data in c.data
  where (data.speed&gt;  item().speed_Value) AND
  (data.timestamp &gt;= '@{formatDateTime(addhours(pipeline().TriggerTime, -1), 'yyyy-MM-ddTHH:mm:ssZ' )}' 
  AND data.timestamp &lt; '@{formatDateTime(pipeline().TriggerTime, 'yyyy-MM-ddTHH:mm:ssZ' )}')
  </code></pre>
  
  <p>I get an error as I run this pipeline:</p>
  
  <pre><code>{
      "errorCode": "2200",
      "message": "Failure happened on 'Source' side. ErrorCode=UserErrorDocumentDBReadError,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=DocumentDb operation failed: Message: {\"errors\":[{\"severity\":\"Error\",\"location\":{\"start\":231,\"end\":235},\"code\":\"SC2005\",\"message\":\"'item' is not a recognized built-in function name.\"}]}\r\nActivityId: *redacted*, documentdb-dotnet-sdk/1.21.1 Host/64-bit MicrosoftWindowsNT/6.2.9200.0.,Source=Microsoft.DataTransfer.ClientLibrary.DocumentDb,''Type=Microsoft.Azure.Documents.BadRequestException,Message=Message: {\"errors\":[{\"severity\":\"Error\",\"location\":{\"start\":231,\"end\":235},\"code\":\"SC2005\",\"message\":\"'item' is not a recognized built-in function name.\"}]}\r\nActivityId: redacted, documentdb-dotnet-sdk/1.21.1 Host/64-bit MicrosoftWindowsNT/6.2.9200.0,Source=Microsoft.Azure.Documents.Client,''Type=System.Runtime.InteropServices.COMException,Message=Exception from HRESULT: 0x800A0B00,Source=,'",
      "failureType": "UserError",
      "target": "Copy Data1"
  }
  </code></pre>
  
  <p>It is saying item is not a built in function name.  I want to use value from the foreach activity to query the source.  </p>
  
  <p>Furthermore, here is my dynamic filepath content</p>
  
  <pre><code>@concat('test_', item().speed, '.csv')
  </code></pre>
  
  <p>I get the desired dynamic file structure with this expression, if I am using static values in the query like:   <code>data.speed&gt; 500</code>  </p>