cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MitchG
New Member

IndexOf function not finding the specified string

Hello, writing a flow that is triggered when my team receives an email. The flow creates a task in Microsoft Teams using details that came from the email. This flow works 99% of the time. However there are random times when it does not and I have zero clue why. The issue I think stems from the indexOf function. I'll explain:

 

The grammatical format of the subject of the email that we receive is always the same, where [Title] is the string I'm trying to pull:

 

" Digital Signage request - [Title] - has been approved for processing "  

  

To pull the desired text, I know I need a few things: the text to be searched, the start index, and the length. 

 

I know the first two already: the email subject line, and 26 (I counted the characters where the prefix ends). 

 

To find the third parameter, I use the indexOf function. I search for the index of "has been approved for processing". Then I subtract 26 (the start index) from the start index of "has been approved for processing" to find the string length. 

 

After this I have the parameter necessary to complete the substring function:

- The full email subject

- The start index

- The string length

 

However, there are random times when the indexOf function does not find "has been approved for processing" and instead returns -1. The substring action then fails as a result and it provides me this message:

 

InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2763': 'The template language function 'substring' parameter is out of range: 'start index' must be non-negative integer and should be less than the length of the string. Please see https://aka.ms/logicexpressions#substring for usage details.'.

 

 

Again, the format of the email subject is always the same: " Digital Signage request - [Title] - has been approved for processing "

 

How is the indexOf function finding the "has been approved for processing" string on some emails but not others? Is there something I can do to fix this?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
abm
Super User
Super User

Hi @MitchG 

 

If you want to extract the title of the text 'Digital Signage request - [Title] - has been approved for processing' then use the split function using '-'. Believe you have '-' character between Title.

 

Thanks

 

  



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

2 REPLIES 2
abm
Super User
Super User

Hi @MitchG 

 

If you want to extract the title of the text 'Digital Signage request - [Title] - has been approved for processing' then use the split function using '-'. Believe you have '-' character between Title.

 

Thanks

 

  



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

v-alzhan-msft
Community Support
Community Support

Hi @MitchG ,

 

Please share the full email subject and please explain what you want to get from the subject and I would provide a proper workaround for you.

 

Best regards,

Alice       

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,728)