Replacing Variable with value of a pipeline variable in DataFactory

Bert Natenstedt 1 Reputation point
2023-02-28T16:33:12.0666667+00:00

Hello

 In my Azure DataFactory project I need to replace a part of a string with the value of a pipeline variable.

The string is received from a Record in a table source and contains something like this:  ....Fieldname eq {variables('testValue')} 
Conform ADF documentation I think the part between{} should be evaluated by ADF and should be replace by the value of the variable testValue

(I Used this example as test in a set variable action in ADF).

But at this moment in in the debug exactly the string as received from the record is returned. 
It looks like that ADF can't interprete the string as string interpolation when the string is added from a previous activity

Is my assumption correct or is there a solution ?

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

1 answer

Sort by: Most helpful
  1. AnnuKumari-MSFT 34,451 Reputation points Microsoft Employee
    2023-03-02T11:35:19.2+00:00

    @Bert Natenstedt ,

    Welcome to Microsoft Q&A platform and thanks for posting your question here.

    As I understand your query, you want to replace the string '{variables('testValue')}' to the value holded by variable. For this you tried using set variable activity , however, adf is returning the same input string as output. Please let me know if that is not the correct understanding.

    I tried to reproduce your case, it looks like the symbols are not being treated as a valid string when we use replace function .

    The workaround I would suggest is to remove all the symbols by the following expression

    and then replace the remaining string variables(testValue) with the variable value.

    So here is the reference video of the pipeline.

    1. Use lookup activity to fetch the table content
    2. Associate two set variable activities with it. First one referencing var1 with this expresion:
       @replace(replace(replace(replace(activity('Lookup1').output.firstRow.col1,'{',''),'}',''),'\',''),'"','')
       
    

    And second set variable referencing var2 having the value you specified , say, 'GUID'

    1. Add another set variable activity to replace 'variables(testValue)' with 'GUID'
       @replace(variables('var1'),'variables(testValue)',variables('var2'))
       
    

    setvar


    Hope it helps. Please accept the answer and mark it as helpful. Thanks


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.