cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
akg1421
Advocate II
Advocate II

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

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 

1 ACCEPTED SOLUTION

Accepted Solutions

@Pstork1 The quotes are escaped and managed by the flow and the 'compose' seems to strong type the quotes. Output is a valid string - to be used in HTTP request to SharePoint action. Thanks!

@lbendlin Using the second variable too gives the same error. The issues seems to appear due to the variable 'EmailRcptTo' being referenced twice in 'substring' function. 

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

Once we separate these 2 functions 'substring' and 'sub' via second variable / compose the issue is resolved. Thanks!

@trice602 The extra ","s is at the end of string, the very last character. Thanks for digging deep. Appreciate!

@Chriddle Nice! 'Select' does the job but I find difficult to add character (quotes) in Select>Map so as to 'Join' up the output with a single comma , Tried 'concat' but it didn't work. 

 

 

Problem was resolved by separating the functions 'substring' and 'sub' via second variable or 'Compose'
Untitled.png

 

View solution in original post

12 REPLIES 12
Pstork1
Most Valuable Professional
Most Valuable Professional

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@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
<----------------------------------------->

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

@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
Multi Super User
Multi Super User

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.

@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
Super User
Super User

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.

 

 

 

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn

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
Most Valuable Professional
Most Valuable Professional

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

{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
Super User
Super User

@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.

@Pstork1 The quotes are escaped and managed by the flow and the 'compose' seems to strong type the quotes. Output is a valid string - to be used in HTTP request to SharePoint action. Thanks!

@lbendlin Using the second variable too gives the same error. The issues seems to appear due to the variable 'EmailRcptTo' being referenced twice in 'substring' function. 

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

Once we separate these 2 functions 'substring' and 'sub' via second variable / compose the issue is resolved. Thanks!

@trice602 The extra ","s is at the end of string, the very last character. Thanks for digging deep. Appreciate!

@Chriddle Nice! 'Select' does the job but I find difficult to add character (quotes) in Select>Map so as to 'Join' up the output with a single comma , Tried 'concat' but it didn't work. 

 

 

Problem was resolved by separating the functions 'substring' and 'sub' via second variable or 'Compose'
Untitled.png

 

Chriddle
Super User
Super User

Sorry, but Compose didn't solve your problem.

Your problem no longer occurs because you replaced variables('{EmailRcptTo}') with variables('EmailRcptTo').

 

Related to this:

'Select' does the job but I find difficult to add character (quotes) in Select>Map so as to 'Join' up the output with a single comma , Tried 'concat' but it didn't work. 

 

Use the Select action to map the "Manager" objects to the "Manager Email"s.

Then you simply need to join this array of emails in a Compose action:

 

join(body('Select'), ',')

or even write this expression into the Send an email action

 

 

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (2,892)