data factory foreach activity incorrect set variable

arkiboys 9,686 Reputation points
2024-08-19T11:03:25.4433333+00:00

Hello,in the the foreach activity, I have a set variable and a copy activity.the set variable assigns the variable to the correct text as follows:i.e. if source_entity is 'comment' then set the variable to 'LastEditDate' otherwise, set it to 'LastModifiedDate'

@if(equals(tolower(item().source_entity), 'comment'), 'LastEditDate', 'LastModifiedDate')

then in the source tab of the copy activity I am trying to use this variable but it does not seem to get assigned correctly.

@concat('SELECT * FROM ', item().source_entity, ' WHERE ',variables('v_modified_date_column'),' >= ',variables('v_last_modified_date_as_of'),'T00:00:00Z')

It looks like, this works fine if I tick the sequential property of the foreach activity but if it is not ticked then the variable does not seem to assign correctly...I do not want the sequential as there are alot of items to loop through...

Any thoughts?

thank you

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,521 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 22,616 Reputation points
    2024-08-19T11:36:15.71+00:00

    Instead of setting the variable within a ForEach loop, why don't you try to handle the logic within the Copy Activity or Lookup activity itself dynamically? at least you will keep the variable setting logic scoped to the current iteration.

    In your Copy Activity, try the following :

    @concat('SELECT * FROM ', item().source_entity, ' WHERE ', 
    if(equals(tolower(item().source_entity), 'comment'), 'LastEditDate', 'LastModifiedDate'),
    ' >= ', variables('v_last_modified_date_as_of'),'T00:00:00Z')
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.