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 / Iterating over the lin...
Power Automate
Answered

Iterating over the lines of a text file and using StartsWith()

(0) ShareShare
ReportReport
Posted on by 9

I read in a text file and iterate over it line by line using a for-each loop. Inside the loop I have an "if statement" that needs to test if the current line of text starts with a specific string (see screenshot).

 

I thought that using:

=StartsWith(CurrentItem, "<slide")

was the correct way to write the "if condition" but that results in the error:

Invalid argument type (Record). Expecting a Text value instead.

 

What is the correct way to refer to the text in CurrentItem within the StartsWith() function? TIA!

 

pad.png

I have the same question (0)
  • sergiopereira83 Profile Picture
    25 on at

    You need split the text with new line delimiter before iteration.

     

    sergiopereira83_0-1711814941560.png

     

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @ThomTT 

     

    It appears that you've developed your flow using Power FX, which is currently in the preview stage and lacks comprehensive documentation from Microsoft. Therefore, I kindly request you to consider creating the flow by disabling Power FX, as shown in the screenshot below.

     

    Deenuji_0-1711816915102.png

    After disabling power fx and recreate flow like below:

    Deenuji_3-1711817186120.png

     

    Full flow screenshot:

    Deenuji_2-1711817161842.png

    Code:

    File.ReadTextFromFile.ReadTextAsList File: $'''C:\\Deenu\\slide.txt''' Encoding: File.TextFileEncoding.UTF8 Contents=> FileContents
    LOOP FOREACH CurrentItem IN FileContents
     IF StartsWith(CurrentItem, $'''<slide''', True) THEN
     Display.ShowMessageDialog.ShowMessage Title: $'''sd''' Message: $'''slide exists''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
     END
    END

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

  • ThomTT Profile Picture
    9 on at

    The "read from text file" connector can be configured to returns a list where each element is a line of text. There is no need to manually split the text.

     

    But even if I do manually split the text, the "if" statement still has the same issue.

     

     

  • ThomTT Profile Picture
    9 on at
    Thank you Deenuji - that was my problem. I recreated my flow without selecting Power FX and everything works as you explained.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 245

#2
David_MA Profile Picture

David_MA 216 Super User 2026 Season 1

#3
Valantis Profile Picture

Valantis 212

Last 30 days Overall leaderboard