cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ian_C
Helper II
Helper II

New designer issue - Avoiding recursive loops

I have a basic workflow which relates to a Sharepoint list with one text field and one (single select) choice field.

The workflow consists of:
Sharepoint Trigger - When an item is created or modified

Get item - using id from trigger

Condition statement  - testing whether the "modified by email" was the system email account (under which I wrote the workflow)

If true then terminate

If false then update item

  

Prior to the new designer layout I have written all my workflows to test the "Modified by email"  to avoid recursive loops and terminate the workflows and everything was fine, I could test the "Modified by in either the trigger or the Get item action. No problem.

 

However in the new designer world If I add a Get item action under the trigger it immediately wraps it in a "For each" loop, my condition statement then causes the workflow to fail with : 
'The template language expression 'body('Get_item')?['Editor']?['Email']' cannot be evaluated because property 'Editor' cannot be selected. Array elements can only be selected using an integer index.

Alternatively if I point my condition statement to the modified by email field trigger then the designer encapsulates that into a for each loop and I can't subsequently have a terminate statement inside that.

I have tried switching to classic designer and it does exactly the same thing. 
What has changed and how do we now go about avoiding recursive loops?

 

Many thanks

15 REPLIES 15
Rhiassuring
Super User
Super User

Try this as the expression in your condition. No need to "Get Item". 

 

triggerOutputs()?['body/value'][0]?['Editor/Email']

 

Rhiassuring_0-1701809269505.png

 

 

Or,  you could just use it as a trigger condition (available through the Settings in the Trigger) and forego the condition in the flow entirely: 

 

@not(equals(triggerBody()?['value'][0]?['Editor/email'],'rhia@email.com'))

 

This means it will only run if the Modified By is NOT "rhia@email.com".

 

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



David_MA
Super User
Super User

If one of @Rhiassuring's suggestions does not work, you can switch to the old designer by clicking on the three dots at the top-right of the screen:

David_MA_0-1701810207259.png

Of course, I don't know how long this will be allowed until we're all forced to use the new designer. Are you enjoying the new designer? It seems like a step backward to me.

wskinnermctc
Super User
Super User

@Ian_C Why do you need to use a "Get Item" action? The outputs should be the same for the trigger as the Get Item. Seems to be redundant.

Doesn't solve your apply to each issue, but curious about needing to use Get Item.

@wskinnermctc Hi, I used the "Get item" action on occasion where I've needed to change the trigger, plus it also makes for easier visual debugging.

@Rhiassuring Thanks I'll give this a go and report back

 

@David_MA Thanks I tried switching back using the three dots however this still had the same effect. 
It's like the Sharepoint Trigger - When an item is created or modified and the  Get item action - using id from the trigger are returning arrays rather than the single item.

That was happening to me as well (wanted to see what would happen if I switched with that flow.) I think you'd need to build it from scratch in Classic to not experience the weird "get item" situation.

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



@Rhiassuring Thanks, the option to build from classic seems to be no longer available, selecting create automatically starts the new designer

 

Thanks @Rhiassuring  your code in the condition works so I can stop the recursive loops. 

I tried putting your code into the trigger settings so that I wouldn't need the condition check 

and it fails with 
Unable to process template language expressions for action 'Condition' at line '0' and column '0': 'The template language expression 'triggerOutputs()?['body/value'][0]?['Editor/Email']' cannot be evaluated because property '0' cannot be selected.

 

This seems to indicate that the trigger is not returning an array however if you do a subsequent "Get Item" or "Update Item" referencing the ID from the trigger it puts the action within a "For each" loop - Most odd.

 

 

Rhiassuring
Super User
Super User

Hi @Ian_C  - note that the formulas I posted are for 2 different scenarios. One for if you continue to use a condition, and one for if you user the trigger condition.

 

The trigger formula is this one:  

 

@not(equals(triggerBody()?['value'][0]?['Editor/email'],'rhia@email.com'))

 

I've just double checked, and it's valid but what I have found, is that you can't "test" for it.

 

Like, if you set the trigger condition and then click "Test" and Automatically or Manual, it won't operate correctly. (Which I think is another thing that has changed lately, as I swear I used to test trigger conditions manually all the time..)

Save it, and go modify something in the library, and see if it runs. In my circumstance, it didn't run when I edited an item as myself, but it did run when Tom Hanks edited the item.

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



Thanks @Rhiassuring I understand about the scenarios. The code for the condition statement (after the trigger) works absolutely fine. (Though I still have superfluous for each loops around any further actions which reference the id in the trigger). 

 

On the other scenario I pasted the code exactly as stated (but with my email) into the actual trigger condition in the settings on the trigger. Then went to the list and added a new entry. Returning to the Flow summary screen (see below) it reported an error with the flow trigger however still ran the flow and then the flow ran again (due to there being an update item action), ignored the trigger condition and was thrown out by the condition statement after the trigger.

So it basically ignored the condition within trigger settings

Ian_C_0-1701939998680.png

Looking at the flow checker it just says there is a problem with the trigger with a link to the trigger which takes me to a blank screen.


Rhiassuring
Super User
Super User

Well that's.. totally bizarre. I'm sorry that's happening. I've now tested my trigger condition twice, with the same outcome both times ... which isn't what you're getting at all! 

@wskinnermctc @ScottShearer @David_MA   any thoughts?

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



This is kind of ridiculous, but I have found a difference depending on how the trigger is created. And/Or if you click Save.

 

I think the problem has to do with the "Done" button that no longer exists in the action settings. In classic view, you had to click Done when changing settings on an action. In Co-Pilot, you just switch between tabs so the flow doesn't really recognize the settings change.

 

So combine the issue of needing to turn on "Split On" when you have the trigger created automatically along with not having an Done button, the flow doesn't recognize the change.

 

Basic Solution 1:

  • Create Brand New Flow with trigger "When an item is created or modified"
  • Go to the Trigger settings, you need to turn the "Split On" to On and use the dropdown to select body/value.
  • Then add a Compose step and type any text in the field so it's not empty.
  • Then click Save

Now the dynamic content is available and does not cause an For Each.

 

Basic Solution 2:

  • Create Brand New Flow with trigger "When an item is created or modified"
  • Delete the Trigger
  • Re-Add the trigger "When an item is created or modified"

The Split On is automatically turned on when you manually create the trigger. The dynamic content is available and does not cause a For Each.

 

This is really silly

Rhiassuring
Super User
Super User

Omg, really? That's a great catch if that's the case, @wskinnermctc 

 

The new designer and all the changes lately make it really difficult to pinpoint things. I'll look forward to seeing if your recommendation works for  Ian.

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



Ian_C
Helper II
Helper II

Hi @wskinnermctc , @Rhiassuring ,
I've tried both the Basic solution 1 and 2 and yes they both work in that they do not create the needless for each loops around a Get item or Update item action. 

It's odd though that you would need to use the "split on" for the trigger as the trigger action should only be actioning one item and not an array (as i understand it the Split-on would cause a separate workflow instance for each item in hte array if there were any).
Surely the trigger "When an item is created or modified" should not be referencing an array in the first place. 

Also it seems now that over this weekend the three dots in the top right hand corner has now changed to a toggle switch now enabling the creation of a workflow and immediately switching back to classic mode. 

The trigger action pre

Helpful resources

Announcements

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 (5,088)