cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

substring works if true but crashes if false

if(contains(triggerBody()['body']['content'],'toto-'),substring(triggerBody()['body']['content'],indexOf(triggerBody()['body']['content'],'toto-'),15),'N/A')

The substring works if true but ....

It shouldn't even get to the substring statement since the result is false

 

Thank you  in advance

5 REPLIES 5
Resident Rockstar
Resident Rockstar

Hi @Anonymous

It would helpful for more detail, images etc to get a grasp of the conectors, triggers used.

 

Thanks, Alan


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

Proud to be a Flownaut!


Skilled Sharer
Skilled Sharer

Don’t use contains. It doesn’t do what you think it does!

In this case tying using an IndexOf() > -1 as your test.

Contains is specifically for whether a collection contains an object. Not a string contains that we might be used to.

- Mark
Anonymous
Not applicable

still crashes

 

Capture.PNG 

if(greater(indexOf(triggerBody()['body']['content'],'toto-'),-1),substring(triggerBody()['body']['content'],indexOf(triggerBody()['body']['content'],'toto-'),15),'N/A')

 

Ok, I see whats wrong with your substring. The sum of the StartIndex and Legth is going to be greater than the total lenght of the string.

 

because you are asking for the IndexOf "toto-" and asking for exactly 15 characters after that we have to assume your string will always be longer than the sum of those two.

 

The easiest way to resolve this is to throw in a load of compose actions for each part of your expression. write out the "length" of your intial string. Another or the output of the indexOf, etc. You might find you need to start your substring at indexOf()+5 (the length of the toto- string). And also ensure there are 15 characters available in the full string for that to work. Also, bear in mind that when referencing your string in this way the position references are 0-based (so the start of the substring).. that means the first item is zero and the second character is 1... whereas the Length references are 1-based. Just to make everything REALLY confusing.

 

So.. take each atomic part of your expression. Write each bit out into a separate compose action and you should see where your numbers don't add up.  Feel free to paste the output of the Compose actions here for us to help more.

 

By the way, the method isnt crashing, it's working perfectly!!

 

- Mark

 

 

Anonymous
Not applicable

it only crashes when its false and the substring section is the true condition it's not even supposed to consider any of this statement

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Top Kudoed Authors
Users online (9,159)