web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Error in variable init...
Power Automate
Answered

Error in variable initialization: String variable must be initialized before it can be used inside action Set variable

(0) ShareShare
ReportReport
Posted on by 195

1- Initialize a 'string' variable to "email@domain.com",

2- Append to variable with dynamic column email

3- Extract substring from created string to eliminate last extra comma ','  e.g.

"email1@xyz.com","email2@xyz.com","email3@xyz.com",

 

2023-09-06 18_47_30-Edit your flow _ Power Automate.png

 

Even though the variable is initialized in first step why then on save it gives error

"Flow save failed with code 'InvalidVariableOperation' and message 'The inputs of workflow run action 'Set_EmailRcptTo_variable' of type 'SetVariable' are not valid. The variable '{EmailRcptTo}' must be initialized before it can be used inside action 'Set_EmailRcptTo_variable'.'."

2023-09-06 19_00_42-Edit your flow _ Power Automate.png

 

Please note I am doing following:

1- Initialize string variable

2- Append to string variable

3- Set string variable

 

Requirement:

1- Create a string initialize it with a sample email all quotes and comma separated "abc@xyz.com",

2- Add to the string dynamic email values from SP column, all enclosed values with quotes "" and a comma e.g. "email1@xyz.com","email2@xyz.com","email3@xyz.com",

3- Remove the last extra comma character


@trice602 @ManishSolanki @creativeopinion @wskinnermctc @Expiscornovus @abm @rzaneti @Pstork1 @Nived_Nambiar @Chriddle @Matthy79 @AlexEncodian @LinnZawWin @Ryan_B @ChristianAbata @SudeepGhatakNZ @Tim19943 @annetoal @tom_riha @Robotech12 @lbendlin 

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    69,129 Most Valuable Professional on at

    I suspect the problem is the use of double quotes in the first initialization.  You are embedding quotes inside a string variable without escaping them.  Try doing the same thing but without the double quotes.

  • efialttes Profile Picture
    14,756 on at

    @akg1421
    Please also note just in case you have two 'Apply to each' nested (une inside the other), you cannot initialize variable inside an 'Apply to each'; you should initialize it before
    Hope this helps
    <----------------------------------------->

  • amk1421 Profile Picture
    195 on at

    @Pstork1 @efialttes Double quotes are absolutely required in first initialization, the string must contain a value like "email1@xyz.com","email2@xyz.com","email3@xyz.com", 

    How should I escape the quote character?

     

    Please note I am doing following:

    1- Initialize string variable

    2- Append to string variable

    3- Set string variable

     

    Requirement:

    1- Create a string initialize it with a sample email all quotes and comma separated "abc@xyz.com",

    2- Add to the string dynamic email values from SP column, all enclosed values with quotes "" and a comma e.g. "email1@xyz.com","email2@xyz.com","email3@xyz.com",

    3- Remove the last extra comma character

     

    Any other way to achieve the same?

  • lbendlin Profile Picture
    8,649 Super User 2026 Season 1 on at

    I got a nicer error message:

     

    Flow save failed with code 'WorkflowRunActionInputsInvalidProperty' and message 'The inputs of workflow run action 'Set_variable' of type 'SetVariable' are not valid. Self reference is not supported when updating the value of variable 'Variable00'.'.

     

    Use a second variable.

  • amk1421 Profile Picture
    195 on at

    @lbendlin So I tried using second variable but it still gives the same error. Issue seems to be because the Initialized variable is getting used in substring function in Set Action

     

    substring(variables('{EmailRcptTo}'), 0, sub(length(variables('{EmailRcptTo}')),1))

     

  • trice602 Profile Picture
    16,071 Super User 2026 Season 1 on at

    Hi @akg1421 ,

     

    I didn't see any extra ","s and here is my test flow.  Please review.

     

    trice602_0-1694014089240.png

     

    trice602_1-1694014117701.png

     

    trice602_2-1694014144989.png

     

    trice602_3-1694014178469.png

     

    trice602_4-1694014199841.png

    Let me know if this helps you resolve this please!  I threw this in a compose at the end so you can see the format.

     

     

     

  • lbendlin Profile Picture
    8,649 Super User 2026 Season 1 on at

    I seem to be able to do this

     

    lbendlin_0-1694014461240.png

     

    lbendlin_1-1694014496626.png

    Also with init/set

     

    lbendlin_2-1694014614026.png

     

  • Pstork1 Profile Picture
    69,129 Most Valuable Professional on at

    The point is that the double quotes are allready there around the value you put in the field because its a string.  What you are trying to define in the variable is the equvalent of this.

     

    ""email1@xyz.com","email2@xyz.com","email3@xyz.com""

     

    That's not a valid string and that's why you are getting the error.  Why do you need the quotes?  If you want to use the list of email addresses in something like the To: field of a mail action the quotes can't be there anyway.

     

    If you insist on having the quotes then use a Compose and append to it using Conact().  The Compose won't strong type the value as a string.

  • Chriddle Profile Picture
    8,672 Super User 2026 Season 1 on at

    {EmailRcptTo} is not the name of your variable, it's EmailRcptTo

    Therefore try variables('EmailRcptTo')

     

    But you might have already noticed, that - since self referencing is not allowed - you can't use that in the Set variable action.

     

    To circumvent this, you may put this into a Compose action and use that output in the Set variable.

     

    However, I would try completely a different aprroach by using a Select action to create the array of emails and simply join its values.

  • Matthy79 Profile Picture
    4,188 Super User 2024 Season 1 on at

    @akg1421 

     

    First of all. It’s not ok to tag the half community during topic creation.

     

    You already got your reply why this can’t work (self reference)

     

    What I don’t understand is why nobody mentioned the flow setup. Why do you need a variable? Why an apply to each. As far as I understand you have an array and want to use this array to create one single string. This is a classic requirement that can be solved by using select and join.

     

    @Chriddle already mentioned it and that’s the way to go.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 605

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard