cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Resident Rockstar
Resident Rockstar

Re: substring works if true but crashes if false

Hi @Bigchaor

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

Re: substring works if true but crashes if false

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
Highlighted
Frequent Visitor

Re: substring works if true but crashes if false

still crashes

 

Capture.PNG 

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

Re: substring works if true but crashes if false

 

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

 

 

Highlighted
Frequent Visitor

Re: substring works if true but crashes if false

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
firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Users online (7,663)